Skip to content

Commit

Permalink
Merge pull request #27 from gone-io/feature/1.x
Browse files Browse the repository at this point in the history
fix: templates of tools/gone
  • Loading branch information
Degfy authored Jun 15, 2024
2 parents e2266be + ed0a62e commit e1070c0
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 11 deletions.
22 changes: 22 additions & 0 deletions goner/gin/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,38 @@ type router struct {
htmlTpl string `gone:"config,server.html-tpl-pattern"`
mode string `gone:"config,server.mode,default=release"`

gone.Logger `gone:"*"`
HandleProxyToGin `gone:"gone-gin-proxy"`
}

type writer struct {
write func(p []byte) (n int, err error)
}

func (w writer) Write(p []byte) (n int, err error) {
return w.write(p)
}

func (r *router) AfterRevive() gone.AfterReviveError {
gin.SetMode(r.mode)
r.Engine = gin.New()

if r.htmlTpl != "" {
r.Engine.LoadHTMLGlob(r.htmlTpl)
}

gin.DefaultWriter = writer{
write: func(p []byte) (n int, err error) {
r.Debugf("%s", p)
return len(p), nil
},
}
gin.DefaultErrorWriter = writer{
write: func(p []byte) (n int, err error) {
r.Errorf("%s", p)
return len(p), nil
},
}
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion templates/web+mysql/config/local.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# 本地开发环境会读取该文件的配置
server.env=dev
server.env=dev

log.level=debug
2 changes: 1 addition & 1 deletion templates/web+mysql/internal/controller/demo_ctr.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewDemoController() gone.Goner {
type demoController struct {
gone.Flag
demoSvc service.IDemo `gone:"*"`
gone.Logger `gone:"gone-logger"`
gone.Logger `gone:"*"`
authRouter gone.IRouter `gone:"router-auth"`
pubRouter gone.IRouter `gone:"router-pub"`
Expand Down
2 changes: 1 addition & 1 deletion templates/web+mysql/internal/middleware/authorize.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewAuthorizeMiddleware() gone.Goner {

type AuthorizeMiddleware struct {
gone.Flag
gone.Logger `gone:"gone-logger"`
gone.Logger `gone:"*"`
userKey string `gone:"config,auth.user-key"`
}

Expand Down
2 changes: 1 addition & 1 deletion templates/web+mysql/internal/middleware/pub.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewPlantMiddleware() gone.Goner {
// PubMiddleware 公共中间件
type PubMiddleware struct {
gone.Flag
gone.Logger `gone:"gone-logger"`
gone.Logger `gone:"*"`
}

func (m *PubMiddleware) Next(ctx *gone.Context) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion templates/web+mysql/internal/module/demo/db.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewDb() gone.Goner {

type db struct {
gone.Flag
gone.XormEngine `gone:"gone-xorm"`
gone.XormEngine `gone:"*"`
}

func (d *db) createUser(user *entity.User) error {
Expand Down
2 changes: 1 addition & 1 deletion templates/web+mysql/internal/router/auth_router.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewAuth() (gone.Goner, gone.GonerId) {
type authRouter struct {
gone.Flag
gone.IRouter
root gone.IRouter `gone:"gone-gin-router"`
root gone.RouteGroup `gone:"*"`
auth *middleware.AuthorizeMiddleware `gone:"*"`
pub *middleware.PubMiddleware `gone:"*"`
Expand Down
2 changes: 1 addition & 1 deletion templates/web+mysql/internal/router/pub_router.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewPubRouter() (gone.Goner, gone.GonerId) {
type pubRouter struct {
gone.Flag
gone.IRouter
root gone.IRouter `gone:"gone-gin-router"`
root gone.RouteGroup `gone:"*"`
pub *middleware.PubMiddleware `gone:"*"`
}

Expand Down
2 changes: 1 addition & 1 deletion templates/web/internal/middleware/authorize.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewAuthorizeMiddleware() gone.Goner {

type AuthorizeMiddleware struct {
gone.Flag
gone.Logger `gone:"gone-logger"`
gone.Logger `gone:"*"`
userKey string `gone:"config,auth.user-key"`
}

Expand Down
2 changes: 1 addition & 1 deletion templates/web/internal/middleware/pub.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewPlantMiddleware() gone.Goner {
// PubMiddleware 公共中间件
type PubMiddleware struct {
gone.Flag
gone.Logger `gone:"gone-logger"`
gone.Logger `gone:"*"`
}

func (m *PubMiddleware) Next(ctx *gone.Context) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion templates/web/internal/router/auth_router.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewAuth() (gone.Goner, gone.GonerId) {
type authRouter struct {
gone.Flag
gone.IRouter
root gone.IRouter `gone:"gone-gin-router"`
root gone.RouteGroup `gone:"*"`
auth *middleware.AuthorizeMiddleware `gone:"*"`
pub *middleware.PubMiddleware `gone:"*"`
Expand Down
6 changes: 5 additions & 1 deletion tomb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import (
)

func NewTomb(goner Goner) Tomb {
return &tomb{goner: goner, defaultTypes: make(map[reflect.Type]void)}
return &tomb{
goner: goner,
defaultTypes: make(map[reflect.Type]void),
order: Order3,
}
}

type void struct{}
Expand Down

0 comments on commit e1070c0

Please sign in to comment.