feat: Support projectPkg template variables in config, handler, logic, main, and svc template files (#4939)

This commit is contained in:
geekeryy
2025-08-19 20:29:41 +08:00
committed by GitHub
parent 20d20ef861
commit 73d6fcfccd
11 changed files with 42 additions and 34 deletions

View File

@@ -23,10 +23,10 @@ var (
sseLogicTemplate string
)
func genLogic(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error {
func genLogic(dir, rootPkg, projectPkg string, cfg *config.Config, api *spec.ApiSpec) error {
for _, g := range api.Service.Groups {
for _, r := range g.Routes {
err := genLogicByRoute(dir, rootPkg, cfg, g, r)
err := genLogicByRoute(dir, rootPkg, projectPkg, cfg, g, r)
if err != nil {
return err
}
@@ -35,7 +35,7 @@ func genLogic(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
return nil
}
func genLogicByRoute(dir, rootPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
func genLogicByRoute(dir, rootPkg, projectPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
logic := getLogicName(route)
goFile, err := format.FileNamingFormat(cfg.NamingFormat, logic)
if err != nil {
@@ -91,6 +91,7 @@ func genLogicByRoute(dir, rootPkg string, cfg *config.Config, group spec.Group,
"request": requestString,
"hasDoc": len(route.JoinedDoc()) > 0,
"doc": getDoc(route.JoinedDoc()),
"projectPkg": projectPkg,
},
})
}