fix: templates of tools/gone

This commit is contained in:
dapeng 2024-06-15 14:09:49 +08:00
parent c0a5380829
commit ed0a62e7bb
12 changed files with 39 additions and 11 deletions

View File

@ -23,9 +23,18 @@ 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()
@ -33,6 +42,19 @@ func (r *router) AfterRevive() gone.AfterReviveError {
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
}

View File

@ -1,2 +1,4 @@
# 本地开发环境会读取该文件的配置
server.env=dev
server.env=dev
log.level=debug

View File

@ -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"`

View File

@ -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"`
}

View File

@ -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) {

View File

@ -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 {

View File

@ -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:"*"`

View File

@ -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:"*"`
}

View File

@ -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"`
}

View File

@ -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) {

View File

@ -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:"*"`

View File

@ -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{}