|
|
@ -28,32 +28,38 @@ func getParentPackage(dir string) (string, error) {
|
|
|
|
var tempPath = absDir
|
|
|
|
var tempPath = absDir
|
|
|
|
var hasGoMod = false
|
|
|
|
var hasGoMod = false
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
if tempPath == filepath.Dir(tempPath) {
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tempPath = filepath.Dir(tempPath)
|
|
|
|
|
|
|
|
if goctlutil.FileExists(filepath.Join(tempPath, goModeIdentifier)) {
|
|
|
|
if goctlutil.FileExists(filepath.Join(tempPath, goModeIdentifier)) {
|
|
|
|
tempPath = filepath.Dir(tempPath)
|
|
|
|
tempPath = filepath.Dir(tempPath)
|
|
|
|
rootPath = absDir[len(tempPath)+1:]
|
|
|
|
rootPath = absDir[len(tempPath)+1:]
|
|
|
|
hasGoMod = true
|
|
|
|
hasGoMod = true
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if tempPath == filepath.Dir(tempPath) {
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tempPath = filepath.Dir(tempPath)
|
|
|
|
if tempPath == string(filepath.Separator) {
|
|
|
|
if tempPath == string(filepath.Separator) {
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !hasGoMod {
|
|
|
|
|
|
|
|
|
|
|
|
if hasGoMod {
|
|
|
|
|
|
|
|
return rootPath, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
parent := path.Join(gopath, "src")
|
|
|
|
parent := path.Join(gopath, "src")
|
|
|
|
pos := strings.Index(absDir, parent)
|
|
|
|
pos := strings.Index(absDir, parent)
|
|
|
|
if pos < 0 {
|
|
|
|
if pos < 0 {
|
|
|
|
fmt.Printf("%s not in gomod project path, or not in GOPATH of %s directory\n", absDir, gopath)
|
|
|
|
fmt.Printf("%s not in go.mod project path, or not in GOPATH of %s directory\n", absDir, gopath)
|
|
|
|
tempPath = filepath.Dir(absDir)
|
|
|
|
tempPath = filepath.Dir(absDir)
|
|
|
|
rootPath = absDir[len(tempPath)+1:]
|
|
|
|
rootPath = absDir[len(tempPath)+1:]
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rootPath = absDir[len(parent)+1:]
|
|
|
|
rootPath = absDir[len(parent)+1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rootPath, nil
|
|
|
|
return rootPath, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|