Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: templates of tools/gone #27

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 35 in goner/gin/router.go

View check run for this annotation

Codecov / codecov/patch

goner/gin/router.go#L34-L35

Added lines #L34 - L35 were not covered by tests
}

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
},

Check warning on line 50 in goner/gin/router.go

View check run for this annotation

Codecov / codecov/patch

goner/gin/router.go#L48-L50

Added lines #L48 - L50 were not covered by tests
}
gin.DefaultErrorWriter = writer{
write: func(p []byte) (n int, err error) {
r.Errorf("%s", p)
return len(p), nil
},

Check warning on line 56 in goner/gin/router.go

View check run for this annotation

Codecov / codecov/patch

goner/gin/router.go#L54-L56

Added lines #L54 - L56 were not covered by tests
}
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