Refactoring: improve behavior of Gopaths() and Gopath()
diff --git a/cmd/link_package.go b/cmd/link_package.go
index b0e3986..3519ed3 100644
--- a/cmd/link_package.go
+++ b/cmd/link_package.go
@@ -21,7 +21,7 @@
here := "../.." + strings.Repeat("/..", depth)
gopath := Gopath()
- if len(gopath) == 0 {
+ if gopath == "" {
return nil, fmt.Errorf("$GOPATH appears to be unset")
}
if len(pname) == 0 {
diff --git a/cmd/util.go b/cmd/util.go
index ba6ab17..9169f54 100644
--- a/cmd/util.go
+++ b/cmd/util.go
@@ -65,15 +65,12 @@
// CowardMode checks that the environment is setup before continuing on. If not
// setup and error is returned.
func CowardMode(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
- gopath := Gopaths()
- if len(gopath) == 0 {
+ gopath := Gopath()
+ if gopath == "" {
return false, fmt.Errorf("No GOPATH is set.\n")
}
- if len(gopath[0]) == 0 {
- return false, fmt.Errorf("GOPATH cannot be empty.\n")
- }
- _, err := os.Stat(path.Join(gopath[0], "src"))
+ _, err := os.Stat(path.Join(gopath, "src"))
if err != nil {
Error("Could not find %s/src.\n", gopath)
Info("As of Glide 0.5/Go 1.5, this is required.\n")
@@ -108,7 +105,11 @@
// This should be used carefully. If, for example, you are looking for a package,
// you may be better off using Gopaths.
func Gopath() string {
- return Gopaths()[0]
+ gopaths := Gopaths()
+ if len(gopaths) == 0 {
+ return ""
+ }
+ return gopaths[0]
}
// Gopaths retrieves the Gopath as a list when there is more than one path
@@ -116,11 +117,7 @@
func Gopaths() []string {
p := os.Getenv("GOPATH")
p = strings.Trim(p, string(filepath.ListSeparator))
- ps := filepath.SplitList(p)
- if len(ps) == 0 {
- return []string{"."}
- }
- return ps
+ return filepath.SplitList(p)
}
// BuildCtxt is a convenience wrapper for not having to import go/build