From 02a026f7634d15c40448b4f0824b24d6e921a9f7 Mon Sep 17 00:00:00 2001 From: wencan Date: Mon, 25 May 2020 09:33:28 +0800 Subject: [PATCH] support multi-path gopath --- mockgen/parse.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mockgen/parse.go b/mockgen/parse.go index 8ceed121..3177ac1d 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -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 }