You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
786 B
Go
37 lines
786 B
Go
package golang
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/ctx"
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
|
)
|
|
|
|
func GetParentPackage(dir string) (string, error) {
|
|
abs, err := filepath.Abs(dir)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
projectCtx, err := ctx.Prepare(abs)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// fix https://github.com/zeromicro/go-zero/issues/1058
|
|
wd := projectCtx.WorkDir
|
|
d := projectCtx.Dir
|
|
same, err := pathx.SameFile(wd, d)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
trim := strings.TrimPrefix(projectCtx.WorkDir, projectCtx.Dir)
|
|
if same {
|
|
trim = strings.TrimPrefix(strings.ToLower(projectCtx.WorkDir), strings.ToLower(projectCtx.Dir))
|
|
}
|
|
|
|
return filepath.ToSlash(filepath.Join(projectCtx.Path, trim)), nil
|
|
}
|