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

@@ -8,15 +8,15 @@ import (
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
)
func GetParentPackage(dir string) (string, error) {
func GetParentPackage(dir string) (string, string, error) {
abs, err := filepath.Abs(dir)
if err != nil {
return "", err
return "", "", err
}
projectCtx, err := ctx.Prepare(abs)
if err != nil {
return "", err
return "", "", err
}
// fix https://github.com/zeromicro/go-zero/issues/1058
@@ -24,7 +24,7 @@ func GetParentPackage(dir string) (string, error) {
d := projectCtx.Dir
same, err := pathx.SameFile(wd, d)
if err != nil {
return "", err
return "", "", err
}
trim := strings.TrimPrefix(projectCtx.WorkDir, projectCtx.Dir)
@@ -32,5 +32,5 @@ func GetParentPackage(dir string) (string, error) {
trim = strings.TrimPrefix(strings.ToLower(projectCtx.WorkDir), strings.ToLower(projectCtx.Dir))
}
return filepath.ToSlash(filepath.Join(projectCtx.Path, trim)), nil
return filepath.ToSlash(filepath.Join(projectCtx.Path, trim)), projectCtx.Path, nil
}