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>
master
kingxt 4 years ago committed by GitHub
parent 2b815162f6
commit 1d12f20ff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,11 +4,13 @@ import (
"fmt" "fmt"
goformat "go/format" goformat "go/format"
"io" "io"
"path/filepath"
"strings" "strings"
"github.com/tal-tech/go-zero/core/collection" "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/spec"
"github.com/tal-tech/go-zero/tools/goctl/api/util" "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" "github.com/tal-tech/go-zero/tools/goctl/util/project"
) )
@ -17,6 +19,16 @@ func getParentPackage(dir string) (string, error) {
if err != nil { if err != nil {
return "", err 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 return p.GoMod.Module, nil
} }

@ -28,6 +28,7 @@ type (
GoMod struct { GoMod struct {
Module string Module string
Path string
} }
) )
@ -110,6 +111,7 @@ func Prepare(projectDir string, checkGrpcEnv bool) (*Project, error) {
Path: path, Path: path,
GoMod: GoMod{ GoMod: GoMod{
Module: module, Module: module,
Path: goMod,
}, },
}, nil }, nil
} }

Loading…
Cancel
Save