mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Use go/build to get default GOPATH
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -91,8 +89,3 @@ func (p *Parser) Parse(fname string, isDir bool) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getDefaultGoPath() (string, error) {
|
||||
output, err := exec.Command("go", "env", "GOPATH").Output()
|
||||
return string(bytes.TrimSpace(output)), err
|
||||
}
|
||||
|
||||
+2
-5
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"go/build"
|
||||
)
|
||||
|
||||
func getPkgPath(fname string, isDir bool) (string, error) {
|
||||
@@ -137,11 +138,7 @@ func getModulePath(goModPath string) string {
|
||||
func getPkgPathFromGOPATH(fname string, isDir bool) (string, error) {
|
||||
gopath := os.Getenv("GOPATH")
|
||||
if gopath == "" {
|
||||
var err error
|
||||
gopath, err = getDefaultGoPath()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot determine GOPATH: %s", err)
|
||||
}
|
||||
gopath = build.Default.GOPATH
|
||||
}
|
||||
|
||||
for _, p := range strings.Split(gopath, string(filepath.ListSeparator)) {
|
||||
|
||||
Reference in New Issue
Block a user