Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
support multi-path gopath
Browse files Browse the repository at this point in the history
  • Loading branch information
wencan committed May 29, 2020
1 parent 92f53b0 commit 02a026f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mockgen/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,16 @@ func parsePackageImport(srcDir string) (string, error) {
}
}
// fall back to GOPATH mode
goPath := os.Getenv("GOPATH")
if goPath == "" {
goPaths := os.Getenv("GOPATH")
if goPaths == "" {
return "", fmt.Errorf("GOPATH is not set")
}
sourceRoot := filepath.Join(goPath, "src") + string(os.PathSeparator)
if !strings.HasPrefix(srcDir, sourceRoot) {
return "", errOutsideGoPath
goPathList := strings.Split(goPaths, string(os.PathSeparator))
for _, goPath := range goPathList {
sourceRoot := filepath.Join(goPath, "src") + string(os.PathSeparator)
if strings.HasPrefix(srcDir, sourceRoot) {
return filepath.ToSlash(strings.TrimPrefix(srcDir, sourceRoot)), nil
}
}
return filepath.ToSlash(strings.TrimPrefix(srcDir, sourceRoot)), nil
return "", errOutsideGoPath
}

0 comments on commit 02a026f

Please # to comment.