mirror of
https://github.com/astaxie/beego.git
synced 2024-11-04 21:40:56 +00:00
31 lines
569 B
Go
31 lines
569 B
Go
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 ""
|
|
}
|