Merge branch 'stek29-default_gopath'

This commit is contained in:
Alexandr Mayorskiy
2020-04-12 17:44:43 +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
@@ -3,6 +3,7 @@ package parser
import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
"os"
"os/exec"
@@ -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)) {