Skip to content

Commit

Permalink
Merge pull request #91 from Sirikon/ponzu-dev
Browse files Browse the repository at this point in the history
Move getGOPATH method to paths.go
  • Loading branch information
nilslice authored Mar 1, 2017
2 parents ad6220d + a19b16e commit 720367f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
27 changes: 0 additions & 27 deletions cmd/ponzu/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"io"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strings"
)

Expand Down Expand Up @@ -60,31 +58,6 @@ func getAddon(args []string) error {
return nil
}

// resolve GOPATH. In 1.8 can be default, or custom. A custom GOPATH can
// also contain multiple paths, in which case 'go get' uses the first
func getGOPATH() (string, error) {
var gopath string
gopath = os.Getenv("GOPATH")
if gopath == "" {
// not set, find the default
usr, err := user.Current()
if err != nil {
return gopath, err
}
gopath = filepath.Join(usr.HomeDir, "go")
} else {
// parse out in case of multiple, retain first
if runtime.GOOS == "windows" {
gopaths := strings.Split(gopath, ";")
gopath = gopaths[0]
} else {
gopaths := strings.Split(gopath, ":")
gopath = gopaths[0]
}
}
return gopath, nil
}

// this is distinct from copyAll() in that files are copied, not moved,
// since we also need them to remain in $GOPATH/src
// thanks to @markc of stack overflow for the copyFile and copyFileContents functions
Expand Down
33 changes: 32 additions & 1 deletion cmd/ponzu/paths.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package main

import "runtime"
import (
"os"
"os/user"
"path/filepath"
"runtime"
"strings"
)

// buildOutputName returns the correct ponzu-server file name
// based on the host Operating System
Expand All @@ -11,3 +17,28 @@ func buildOutputName() string {

return "ponzu-server"
}

// resolve GOPATH. In 1.8 can be default, or custom. A custom GOPATH can
// also contain multiple paths, in which case 'go get' uses the first
func getGOPATH() (string, error) {
var gopath string
gopath = os.Getenv("GOPATH")
if gopath == "" {
// not set, find the default
usr, err := user.Current()
if err != nil {
return gopath, err
}
gopath = filepath.Join(usr.HomeDir, "go")
} else {
// parse out in case of multiple, retain first
if runtime.GOOS == "windows" {
gopaths := strings.Split(gopath, ";")
gopath = gopaths[0]
} else {
gopaths := strings.Split(gopath, ":")
gopath = gopaths[0]
}
}
return gopath, nil
}

0 comments on commit 720367f

Please sign in to comment.