1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-11 10:40:40 +00:00

support Go1.8 default GOPATH

This commit is contained in:
astaxie
2017-04-24 21:10:03 +08:00
parent 3bb4ca5adc
commit 52f916a28a
2 changed files with 32 additions and 5 deletions

30
utils/utils.go Normal file
View File

@ -0,0 +1,30 @@
package utils
import (
"os"
"path/filepath"
"runtime"
"strings"
)
// GetGOPATHs returns all paths in GOPATH variable.
func GetGOPATHs() []string {
gopath := os.Getenv("GOPATH")
if gopath == "" && strings.Compare(runtime.Version(), "go1.8") >= 0 {
gopath = defaultGOPATH()
}
return filepath.SplitList(gopath)
}
func defaultGOPATH() string {
env := "HOME"
if runtime.GOOS == "windows" {
env = "USERPROFILE"
} else if runtime.GOOS == "plan9" {
env = "home"
}
if home := os.Getenv(env); home != "" {
return filepath.Join(home, "go")
}
return ""
}