Skip to content

Commit

Permalink
optimize gin template file
Browse files Browse the repository at this point in the history
  • Loading branch information
alimy committed Mar 6, 2020
1 parent 543e082 commit c7b25e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions internal/generator/templates/gin_iface.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@ type {{.TypeName}} interface {
{{if .IsNeedChain}}// Chain provide handlers chain for gin
Chain() gin.HandlersChain
{{end}}
{{range .Fields}}{{if notEmptyStr .Comment }}// {{.Comment}}{{end}}
{{.MethodName}}(*gin.Context)
{{end}}
{{range .Fields}}{{if notEmptyStr .Comment }} // {{.Comment}}
{{.MethodName}}(*gin.Context){{else}} {{.MethodName}}(*gin.Context){{end}}{{end}}
}

// Register{{.TypeName}}Servant register {{.TypeName}} servant to gin
func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}) {
{{if notEmptyStr .Group }}router := e.Group({{.Group}}){{else}}router := e{{end}}
{{if .IsNeedChain}}// use chain for router
{{if notEmptyStr .Group }} router := e.Group({{.Group}}){{else}} router := e{{end}}
{{if .IsNeedChain}} // use chain for router
middlewares := s.Chain()
router.Use(middlewares...)
{{end}}

// register routes info to router
{{range .Fields}}
{{if notHttpAny .HttpMethod }}router.Handle({{.HttpMethod}}, "{{.Path}}", s.{{.MethodName}}){{else}}router.Any("{{.Path}}", s.{{.MethodName}}){{end}}
{{end}}
{{range .Fields}}{{if notHttpAny .HttpMethod }}router.Handle({{.HttpMethod}}, "{{.Path}}", s.{{.MethodName}}){{else}}router.Any("{{.Path}}", s.{{.MethodName}}){{end}}{{end}}
}
8 changes: 4 additions & 4 deletions internal/generator/templates_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c7b25e9

Please sign in to comment.