-
Notifications
You must be signed in to change notification settings - Fork 1
/
env.go
49 lines (45 loc) · 1.13 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package errors
import (
"os"
"strings"
"sync"
)
var gopaths = make([]string, 0, 2)
var _gopathOnce = sync.Once{}
func goEnv() []string {
_gopathOnce.Do(func() {
// goroot
goroot := os.Getenv("GOROOT")
if len(goroot) > 0 {
if strings.Contains(goroot, `\`) && strings.Contains(goroot, ":") { // win
goroot = strings.Replace(goroot, `\`, "/", -1)
}
gopaths = append(gopaths, goroot)
}
gopath := os.Getenv("GOPATH")
if len(gopath) == 0 {
return
}
if strings.Contains(gopath, `\`) && strings.Contains(gopath, ":") { // win
gopath = strings.Replace(gopath, `\`, "/", -1)
if strings.Contains(gopath, ";") {
gopaths := strings.Split(gopath, ";")
for _, item := range gopaths {
gopaths = append(gopaths, strings.TrimSpace(item))
}
} else {
gopaths = append(gopaths, strings.TrimSpace(gopath))
}
} else { // unix
if strings.Contains(gopath, ":") {
gopaths := strings.Split(gopath, ":")
for _, item := range gopaths {
gopaths = append(gopaths, strings.TrimSpace(item))
}
} else {
gopaths = append(gopaths, strings.TrimSpace(gopath))
}
}
})
return gopaths
}