@@ -27,12 +27,20 @@ func Install() error {
27
27
}
28
28
29
29
gocmd := mg .GoCmd ()
30
- gopath , err := sh .Output (gocmd , "env" , "GOPATH" )
30
+ // use GOBIN if set in the environment, otherwise fall back to first path
31
+ // in GOPATH environment string
32
+ bin , err := sh .Output (gocmd , "env" , "GOBIN" )
31
33
if err != nil {
32
- return fmt .Errorf ("can't determine GOPATH: %v" , err )
34
+ return fmt .Errorf ("can't determine GOBIN: %v" , err )
35
+ }
36
+ if bin == "" {
37
+ gopath , err := sh .Output (gocmd , "env" , "GOPATH" )
38
+ if err != nil {
39
+ return fmt .Errorf ("can't determine GOPATH: %v" , err )
40
+ }
41
+ paths := strings .Split (gopath , string ([]rune {os .PathListSeparator }))
42
+ bin = filepath .Join (paths [0 ], "bin" )
33
43
}
34
- paths := strings .Split (gopath , string ([]rune {os .PathListSeparator }))
35
- bin := filepath .Join (paths [0 ], "bin" )
36
44
// specifically don't mkdirall, if you have an invalid gopath in the first
37
45
// place, that's not on us to fix.
38
46
if err := os .Mkdir (bin , 0700 ); err != nil && ! os .IsExist (err ) {
0 commit comments