github.com/chaddy81/ponzu@v0.0.0-20200102001432-9bc41b703131/cmd/ponzu/paths.go (about) 1 package main 2 3 import ( 4 "os" 5 "os/user" 6 "path/filepath" 7 "runtime" 8 "strings" 9 ) 10 11 // buildOutputName returns the correct ponzu-server file name 12 // based on the host Operating System 13 func buildOutputName() string { 14 if runtime.GOOS == "windows" { 15 return "ponzu-server.exe" 16 } 17 18 return "ponzu-server" 19 } 20 21 // resolve GOPATH. In 1.8 can be default, or custom. A custom GOPATH can 22 // also contain multiple paths, in which case 'go get' uses the first 23 func getGOPATH() (string, error) { 24 var gopath string 25 gopath = os.Getenv("GOPATH") 26 if gopath == "" { 27 // not set, find the default 28 usr, err := user.Current() 29 if err != nil { 30 return gopath, err 31 } 32 gopath = filepath.Join(usr.HomeDir, "go") 33 } else { 34 // parse out in case of multiple, retain first 35 if runtime.GOOS == "windows" { 36 gopaths := strings.Split(gopath, ";") 37 gopath = gopaths[0] 38 } else { 39 gopaths := strings.Split(gopath, ":") 40 gopath = gopaths[0] 41 } 42 } 43 return gopath, nil 44 }