MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / findProjectRoot

Function findProjectRoot

testutil/test_data_provider.go:43–67  ·  view source on GitHub ↗

findProjectRoot finds the absolute path to the project root by looking for go.mod

()

Source from the content-addressed store, hash-verified

41
42// findProjectRoot finds the absolute path to the project root by looking for go.mod
43func findProjectRoot() (string, error) {
44 // Start from current working directory
45 wd, err := os.Getwd()
46 if err != nil {
47 return "", err
48 }
49
50 // Walk up the directory tree looking for go.mod
51 dir := wd
52 for {
53 goModPath := filepath.Join(dir, "go.mod")
54 if _, err := os.Stat(goModPath); err == nil {
55 // Found go.mod, this is our project root
56 return dir, nil
57 }
58
59 parent := filepath.Dir(dir)
60 if parent == dir {
61 // Reached filesystem root without finding go.mod
62 break
63 }
64 dir = parent
65 }
66 return "", os.ErrNotExist
67}
68
69// Root returns the absolute path to the testdata directory
70func (p *TestDataProvider) Root() string {

Callers 1

NewTestDataProviderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected