break generator when happen error (#192)

Co-authored-by: kim <xutao@xiaoheiban.cn>
master
kingxt 4 years ago committed by GitHub
parent 57079bf4a4
commit 12327fa07d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -60,8 +60,9 @@ func genConfig(dir string, api *spec.ApiSpec) error {
"auth": strings.Join(auths, "\n"),
})
if err != nil {
return nil
return err
}
formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode)
return err

@ -55,6 +55,7 @@ func genEtc(dir string, api *spec.ApiSpec) error {
if err != nil {
return err
}
formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode)
return err

@ -103,7 +103,7 @@ func doGenToFile(dir, handler string, group spec.Group, route spec.Route, handle
buffer := new(bytes.Buffer)
err = template.Must(template.New("handlerTemplate").Parse(text)).Execute(buffer, handleObj)
if err != nil {
return nil
return err
}
formatCode := formatCode(buffer.String())

@ -72,8 +72,9 @@ func genMain(dir string, api *spec.ApiSpec) error {
"serviceName": api.Service.Name,
})
if err != nil {
return nil
return err
}
formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode)
return err

@ -49,8 +49,9 @@ func genMiddleware(dir string, middlewares []string) error {
"name": strings.Title(name),
})
if err != nil {
return nil
return err
}
formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode)
return err

@ -52,7 +52,7 @@ type (
jwtEnabled bool
signatureEnabled bool
authName string
middleware []string
middlewares []string
}
route struct {
method string
@ -92,9 +92,9 @@ func genRoutes(dir string, api *spec.ApiSpec, force bool) error {
}
var routes string
if len(g.middleware) > 0 {
if len(g.middlewares) > 0 {
gbuilder.WriteString("\n}...,")
var params = g.middleware
var params = g.middlewares
for i := range params {
params[i] = "serverCtx." + params[i]
}
@ -143,8 +143,9 @@ func genRoutes(dir string, api *spec.ApiSpec, force bool) error {
"routesAdditions": strings.TrimSpace(builder.String()),
})
if err != nil {
return nil
return err
}
formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode)
return err
@ -206,7 +207,7 @@ func getRoutes(api *spec.ApiSpec) ([]group, error) {
}
if value, ok := apiutil.GetAnnotationValue(g.Annotations, "server", "middleware"); ok {
for _, item := range strings.Split(value, ",") {
groupedRoutes.middleware = append(groupedRoutes.middleware, item)
groupedRoutes.middlewares = append(groupedRoutes.middlewares, item)
}
}
routes = append(routes, groupedRoutes)

@ -90,8 +90,9 @@ func genServiceContext(dir string, api *spec.ApiSpec) error {
"middlewareAssignment": middlewareAssignment,
})
if err != nil {
return nil
return err
}
formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode)
return err

@ -71,8 +71,9 @@ func genTypes(dir string, api *spec.ApiSpec, force bool) error {
"containsTime": api.ContainsTime(),
})
if err != nil {
return nil
return err
}
formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode)
return err

Loading…
Cancel
Save