patch: save missing templates to disk (#1463)

Co-authored-by: anqiansong <anqiansong@bytedance.com>
master
anqiansong 3 years ago committed by GitHub
parent e57fa8ff53
commit c903966fc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -45,6 +45,8 @@ func genMiddleware(dir string, cfg *config.Config, api *spec.ApiSpec) error {
subdir: middlewareDir,
filename: filename + ".go",
templateName: "contextTemplate",
category: category,
templateFile: middlewareImplementCodeFile,
builtinTemplate: middlewareImplementCode,
data: map[string]string{
"name": strings.Title(name),

@ -73,7 +73,12 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
return err
}
gt := template.Must(template.New("groupTemplate").Parse(routesAdditionTemplate))
templateText, err := pathx.LoadTemplate(category, routesAdditionTemplateFile, routesAdditionTemplate)
if err != nil {
return err
}
gt := template.Must(template.New("groupTemplate").Parse(templateText))
for _, g := range groups {
var gbuilder strings.Builder
gbuilder.WriteString("[]rest.Route{")
@ -139,8 +144,8 @@ rest.WithPrefix("%s"),`, g.prefix)
subdir: handlerDir,
filename: routeFilename,
templateName: "routesTemplate",
category: "",
templateFile: "",
category: category,
templateFile: routesTemplateFile,
builtinTemplate: routesTemplate,
data: map[string]string{
"importPackages": genRouteImports(rootPkg, api),

@ -63,8 +63,8 @@ func genTypes(dir string, cfg *config.Config, api *spec.ApiSpec) error {
subdir: typesDir,
filename: typeFilename,
templateName: "typesTemplate",
category: "",
templateFile: "",
category: category,
templateFile: typesTemplateFile,
builtinTemplate: typesTemplate,
data: map[string]interface{}{
"types": val,

@ -15,6 +15,10 @@ const (
handlerTemplateFile = "handler.tpl"
logicTemplateFile = "logic.tpl"
mainTemplateFile = "main.tpl"
middlewareImplementCodeFile = "middleware.tpl"
routesTemplateFile = "routes.tpl"
routesAdditionTemplateFile = "route-addition.tpl"
typesTemplateFile = "types.tpl"
)
var templates = map[string]string{
@ -24,6 +28,10 @@ var templates = map[string]string{
handlerTemplateFile: handlerTemplate,
logicTemplateFile: logicTemplate,
mainTemplateFile: mainTemplate,
middlewareImplementCodeFile: middlewareImplementCode,
routesTemplateFile: routesTemplate,
routesAdditionTemplateFile: routesAdditionTemplate,
typesTemplateFile: typesTemplate,
}
// Category returns the category of the api files.

Loading…
Cancel
Save