From 601a54bfa356e683e439b3ec9c95d48217d0ccce Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Wed, 21 Jun 2017 13:53:24 +0900 Subject: [PATCH] cmd/go-contrib-init: fix get GOPATH env logic Go runtime now uses user homedir+go (i.e. $HOME/go) if GOPATH environment variable is not set. Change-Id: I26d90e07976a5311ea19de8a6e2c63830b802882 Reviewed-on: https://go-review.googlesource.com/46234 Reviewed-by: Brad Fitzpatrick --- cmd/go-contrib-init/contrib.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/go-contrib-init/contrib.go b/cmd/go-contrib-init/contrib.go index edb27d57..3e92f61f 100644 --- a/cmd/go-contrib-init/contrib.go +++ b/cmd/go-contrib-init/contrib.go @@ -12,6 +12,7 @@ import ( "bytes" "flag" "fmt" + "go/build" "io/ioutil" "log" "os" @@ -46,7 +47,7 @@ func detectrepo() string { return "go" } - for _, path := range filepath.SplitList(os.Getenv("GOPATH")) { + for _, path := range filepath.SplitList(build.Default.GOPATH) { rightdir := filepath.Join(path, "src", "golang.org", "x") if strings.HasPrefix(wd, rightdir) { tail := wd[len(rightdir)+1:] @@ -145,7 +146,7 @@ func checkWorkingDir() { } func firstGoPath() string { - list := filepath.SplitList(os.Getenv("GOPATH")) + list := filepath.SplitList(build.Default.GOPATH) if len(list) < 1 { return "" }