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"), "auth": strings.Join(auths, "\n"),
}) })
if err != nil { if err != nil {
return nil return err
} }
formatCode := formatCode(buffer.String()) formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode) _, err = fp.WriteString(formatCode)
return err return err

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

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

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

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

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

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

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

Loading…
Cancel
Save