MCPcopy Index your code
hub / github.com/maruel/panicparse / isGoModule

Method isGoModule

stack/context.go:1011–1033  ·  view source on GitHub ↗

isGoModule returns the string to the directory containing a go.mod file, and the go import path it represents, if found.

(parts []string)

Source from the content-addressed store, hash-verified

1009// isGoModule returns the string to the directory containing a go.mod file, and
1010// the go import path it represents, if found.
1011func (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//

Callers 3

TestIsGomoduleFunction · 0.95
initFunction · 0.95
findRootsMethod · 0.95

Calls 1

pathJoinFunction · 0.85

Tested by 2

TestIsGomoduleFunction · 0.76
initFunction · 0.76