Browse Source

use `go env` check project is `go mod` or not.

pull/687/head
qiantao 4 months ago
parent
commit
4158ab284e
2 changed files with 12 additions and 1 deletions
  1. + 1
    - 1
      generate/swaggergen/g_docs.go
  2. + 11
    - 0
      utils/utils.go

+ 1
- 1
generate/swaggergen/g_docs.go

@ -435,7 +435,7 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) {
pkgRealpath := ""
if os.Getenv(`GO111MODULE`) == `on` {
if bu.IsGOMODULE() {
pkgRealpath = filepath.Join(bu.GetBeeWorkPath(), "..", pkgpath)
} else {
gopaths := bu.GetGOPATHs()

+ 11
- 0
utils/utils.go

@ -452,3 +452,14 @@ func GetGoVersionSkipMinor() string {
strArray := strings.Split(runtime.Version()[2:], `.`)
return strArray[0] + `.` + strArray[1]
}
func IsGOMODULE() bool {
if combinedOutput, e := exec.Command(`go`, `env`).CombinedOutput(); e != nil {
beeLogger.Log.Errorf("i cann't find go.")
} else {
regex := regexp.MustCompile(`GOMOD="?(.+go.mod)"?`)
stringSubmatch := regex.FindStringSubmatch(string(combinedOutput))
return len(stringSubmatch) == 2
}
return false
}

Loading…
Cancel
Save