mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
refactor (#49)
* rebase upstream * rebase * trim no need line * trim no need line * trim no need line * refactor gomod module logic Co-authored-by: kingxt <dream4kingxt@163.com>
This commit is contained in:
parent
2b815162f6
commit
1d12f20ff6
@ -4,11 +4,13 @@ import (
|
||||
"fmt"
|
||||
goformat "go/format"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/collection"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/util"
|
||||
goctlutil "github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/project"
|
||||
)
|
||||
|
||||
@ -17,6 +19,16 @@ func getParentPackage(dir string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(p.GoMod.Path) > 0 {
|
||||
goModePath := filepath.Clean(filepath.Dir(p.GoMod.Path))
|
||||
absPath, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
parent := filepath.Clean(goctlutil.JoinPackages(p.GoMod.Module, absPath[len(goModePath):]))
|
||||
parent = strings.ReplaceAll(parent, "\\", "/")
|
||||
return parent, nil
|
||||
}
|
||||
|
||||
return p.GoMod.Module, nil
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ type (
|
||||
|
||||
GoMod struct {
|
||||
Module string
|
||||
Path string
|
||||
}
|
||||
)
|
||||
|
||||
@ -110,6 +111,7 @@ func Prepare(projectDir string, checkGrpcEnv bool) (*Project, error) {
|
||||
Path: path,
|
||||
GoMod: GoMod{
|
||||
Module: module,
|
||||
Path: goMod,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user