isGoModule returns the string to the directory containing a go.mod file, and the go import path it represents, if found.
(parts []string)
| 1009 | // isGoModule returns the string to the directory containing a go.mod file, and |
| 1010 | // the go import path it represents, if found. |
| 1011 | func (g *gomodCache) isGoModule(parts []string) (string, string) { |
| 1012 | for i := len(parts); i > 0; i-- { |
| 1013 | prefix := pathJoin(parts[:i]...) |
| 1014 | // Was already looked up. |
| 1015 | if _, ok := (*g)[prefix]; ok { |
| 1016 | break |
| 1017 | } |
| 1018 | (*g)[prefix] = struct{}{} |
| 1019 | p := pathJoin(prefix, "go.mod") |
| 1020 | if runtime.GOOS == "windows" { |
| 1021 | p = strings.Replace(p, "/", pathSeparator, -1) |
| 1022 | } |
| 1023 | /* #nosec G304 */ |
| 1024 | b, err := os.ReadFile(p) |
| 1025 | if err != nil { |
| 1026 | continue |
| 1027 | } |
| 1028 | if match := reModule.FindSubmatch(b); match != nil { |
| 1029 | return prefix, string(match[1]) |
| 1030 | } |
| 1031 | } |
| 1032 | return "", "" |
| 1033 | } |
| 1034 | |
| 1035 | // findRoots sets member RemoteGOROOT, RemoteGOPATHs and LocalGomods. |
| 1036 | // |