Sfoglia il codice sorgente

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>
kingxt 4 anni fa
parent
commit
1d12f20ff6
2 ha cambiato i file con 14 aggiunte e 0 eliminazioni
  1. 12 0
      tools/goctl/api/gogen/util.go
  2. 2 0
      tools/goctl/util/project/project.go

+ 12 - 0
tools/goctl/api/gogen/util.go

@@ -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
 }

+ 2 - 0
tools/goctl/util/project/project.go

@@ -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
 }