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

optimized generator formatted code #148

Merged
merged 30 commits into from
Oct 20, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
optimized generator formatted code
  • Loading branch information
kingxt committed Oct 20, 2020
commit e7892346880a86a0c300f6d16ab1854ed71c52cd
6 changes: 5 additions & 1 deletion tools/goctl/api/gogen/genroutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ func genRoutes(dir string, api *spec.ApiSpec, force bool) error {
gt := template.Must(template.New("groupTemplate").Parse(routesAdditionTemplate))
for _, g := range groups {
var gbuilder strings.Builder
gbuilder.WriteString("[]rest.Route{")
for _, r := range g.routes {
fmt.Fprintf(&gbuilder, `
Route{
{
Method: %s,
Path: "%s",
Handler: %s,
},`,
r.method, r.path, r.handler)
}

var jwt string
if g.jwtEnabled {
jwt = fmt.Sprintf("\n rest.WithJwt(serverCtx.Config.%s.AccessSecret),", g.authName)
Expand All @@ -91,6 +93,7 @@ func genRoutes(dir string, api *spec.ApiSpec, force bool) error {

var routes string
if len(g.middleware) > 0 {
gbuilder.WriteString("\n}...,")
var params = g.middleware
for i := range params {
params[i] = "serverCtx." + params[i]
Expand All @@ -99,6 +102,7 @@ func genRoutes(dir string, api *spec.ApiSpec, force bool) error {
routes = fmt.Sprintf("rest.WithMiddlewares(\n[]rest.Middleware{ %s }, \n %s \n),",
middlewareStr, strings.TrimSpace(gbuilder.String()))
} else {
gbuilder.WriteString("\n},")
routes = strings.TrimSpace(gbuilder.String())
}

Expand Down