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

Commit cb00ee4

Browse files
committed
support multi-path gopath
1 parent 92f53b0 commit cb00ee4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mockgen/parse.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,16 @@ func parsePackageImport(srcDir string) (string, error) {
641641
}
642642
}
643643
// fall back to GOPATH mode
644-
goPath := os.Getenv("GOPATH")
645-
if goPath == "" {
644+
goPaths := os.Getenv("GOPATH")
645+
if goPaths == "" {
646646
return "", fmt.Errorf("GOPATH is not set")
647647
}
648-
sourceRoot := filepath.Join(goPath, "src") + string(os.PathSeparator)
649-
if !strings.HasPrefix(srcDir, sourceRoot) {
650-
return "", errOutsideGoPath
648+
goPathList := strings.Split(goPaths, ":")
649+
for _, goPath := range goPathList {
650+
sourceRoot := filepath.Join(goPath, "src") + string(os.PathSeparator)
651+
if strings.HasPrefix(srcDir, sourceRoot) {
652+
return filepath.ToSlash(strings.TrimPrefix(srcDir, sourceRoot)), nil
653+
}
651654
}
652-
return filepath.ToSlash(strings.TrimPrefix(srcDir, sourceRoot)), nil
655+
return "", errOutsideGoPath
653656
}

0 commit comments

Comments
 (0)