Merge branch 'default_gopath' of git://github.com/stek29/easyjson into stek29-default_gopath

This commit is contained in:
Alexandr Mayorskiy
2020-04-12 17:41:58 +03:00
2 changed files with 2 additions and 12 deletions
-7
View File
@@ -1,12 +1,10 @@
package parser
import (
"bytes"
"go/ast"
"go/parser"
"go/token"
"os"
"os/exec"
"strings"
)
@@ -105,11 +103,6 @@ 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
}
func excludeTestFiles(fi os.FileInfo) bool {
return !strings.HasSuffix(fi.Name(), "_test.go")
}
+2 -5
View File
@@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"sync"
"go/build"
)
func getPkgPath(fname string, isDir bool) (string, error) {
@@ -121,11 +122,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)) {