MCPcopy Create free account
hub / github.com/OpenSLO/oslo / FindModuleRoot

Function FindModuleRoot

internal/pathutils/pathutils.go:16–36  ·  view source on GitHub ↗

FindModuleRoot finds the root of the current module. It does so by looking for a go.mod file in the current working directory.

()

Source from the content-addressed store, hash-verified

14// FindModuleRoot finds the root of the current module.
15// It does so by looking for a go.mod file in the current working directory.
16func FindModuleRoot() string {
17 once.Do(func() {
18 dir, err := os.Getwd()
19 if err != nil {
20 panic(err)
21 }
22 dir = filepath.Clean(dir)
23 for {
24 if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !fi.IsDir() {
25 moduleRoot = dir
26 return
27 }
28 d := filepath.Dir(dir)
29 if d == dir {
30 break
31 }
32 dir = d
33 }
34 })
35 return moduleRoot
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…