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

@@ -14,10 +14,10 @@ import (
//go:embed logic_test.tpl
var logicTestTemplate string
func genLogicTest(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error {
func genLogicTest(dir, rootPkg, projectPkg string, cfg *config.Config, api *spec.ApiSpec) error {
for _, g := range api.Service.Groups {
for _, r := range g.Routes {
err := genLogicTestByRoute(dir, rootPkg, cfg, g, r)
err := genLogicTestByRoute(dir, rootPkg, projectPkg, cfg, g, r)
if err != nil {
return err
}
@@ -26,7 +26,7 @@ func genLogicTest(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) er
return nil
}
func genLogicTestByRoute(dir, rootPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
func genLogicTestByRoute(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 {
@@ -73,6 +73,7 @@ func genLogicTestByRoute(dir, rootPkg string, cfg *config.Config, group spec.Gro
"requestType": requestType,
"hasDoc": len(route.JoinedDoc()) > 0,
"doc": getDoc(route.JoinedDoc()),
"projectPkg": projectPkg,
},
})
}