fix goctl path issue on windows

This commit is contained in:
kevin
2020-08-10 17:26:47 +08:00
parent 82ea0fff17
commit ba636187ce
7 changed files with 22 additions and 49 deletions

View File

@@ -1,35 +0,0 @@
package util
import (
"fmt"
"os"
"path"
"strings"
)
func GetFullPackage(pkg string) (string, error) {
dir, err := os.Getwd()
if err != nil {
return "", err
}
pkgPath := path.Join(dir, pkg)
info, err := os.Stat(pkgPath)
if err != nil {
return "", err
}
if !info.IsDir() {
return "", fmt.Errorf("%s is not a directory", pkg)
}
gopath := os.Getenv("GOPATH")
parent := path.Join(gopath, "src")
pos := strings.Index(pkgPath, parent)
if pos < 0 {
return "", fmt.Errorf("%s is not a correct package", pkg)
}
// skip slash
return pkgPath[len(parent)+1:], nil
}

View File

@@ -10,6 +10,12 @@ import (
"github.com/tal-tech/go-zero/tools/goctl/vars"
)
const pkgSep = "/"
func JoinPackages(pkgs ...string) string {
return strings.Join(pkgs, pkgSep)
}
func MkdirIfNotExist(dir string) error {
if len(dir) == 0 {
return nil