Skip to content

Commit

Permalink
add dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
datewu committed Sep 12, 2023
1 parent 40e999c commit 8ae5f68
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
46 changes: 29 additions & 17 deletions cmd/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,33 @@ func serverVersion(a *gtea.App) func(w http.ResponseWriter, r *http.Request) {
}
}

func index(w http.ResponseWriter, r *http.Request) {
view := front.IndexView{}
token, err := r.Cookie("access_token")
if err != nil {
if errors.Is(err, http.ErrNoCookie) {
jsonlog.Info("no cookie found")
func index(a *gtea.App) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
view := front.IndexView{}
if a.Env() == gtea.DevEnv {
view.User = "datewu"
view.Render(w)
return
}
jsonlog.Err(err)
view.Render(w)
return
}
//func (ghLoginHandler) userInfo(token string) (*UserInfo, error) {
g := ghLoginHandler{}
user, err := g.userInfo(token.Value)
if err != nil {
token, err := r.Cookie("access_token")
if err != nil {
if errors.Is(err, http.ErrNoCookie) {
jsonlog.Info("no cookie found")
}
jsonlog.Err(err)
view.Render(w)
return
}
//func (ghLoginHandler) userInfo(token string) (*UserInfo, error) {
g := ghLoginHandler{}
user, err := g.userInfo(token.Value)
if err != nil {
view.Render(w)
return
}
view.User = user.Login
view.Render(w)
return
}
view.User = user.Login
view.Render(w)
}

type curlCmd struct {
Expand Down Expand Up @@ -288,6 +295,11 @@ type myHandler struct {

func (m *myHandler) middlerware(next http.HandlerFunc) http.HandlerFunc {
middle := func(w http.ResponseWriter, r *http.Request) {
if m.app.Env() == gtea.DevEnv {
m.user = "datewu"
next(w, r)
return
}
co, err := r.Cookie("access_token")
if err != nil {
handler.BadRequestMsg(w, "missing access_token cookie")
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func New(app *gtea.App) http.Handler {
Root: "front/static",
}
r.ServeFSWithGzip("/static", fs)
r.Get("/", index)
r.Get("/", index(app))
r.Get("/version", serverVersion(app))
loginRoutes(app, r)
myRoutes(app, r)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/datewu/set-img
go 1.21.1

require (
github.com/datewu/gtea v0.5.5
github.com/datewu/gtea v0.5.6
k8s.io/api v0.28.1
k8s.io/apimachinery v0.28.1
k8s.io/client-go v0.28.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/datewu/gtea v0.5.5 h1:P9GV1w3dO6ImbJJRMuhf0B87DIz72uzqlq29JUGI36A=
github.com/datewu/gtea v0.5.5/go.mod h1:8Gk1F47xW8SD+NGHoxtNp2HNCTL3agQGxoIX+EzFEhA=
github.com/datewu/gtea v0.5.6 h1:aqSx+yt5c54oSTfbmN3sATtq6mj9eTaxohzcIWMBWp8=
github.com/datewu/gtea v0.5.6/go.mod h1:LgZG3jJfcx6+b4FHHQ9rFuCDS303mH0PGtcforWiXbs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit 8ae5f68

Please sign in to comment.