FindModuleRoot finds the root of the current module. It does so by looking for a go.mod file in the current working directory.
()
| 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. |
| 16 | func 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…