You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
436 B
Go

package file
import (
"os"
"path/filepath"
)
// ProjectRoot returns the root folder of the project
func ProjectRoot() string {
dir, err := os.Getwd()
if err != nil {
panic(err)
}
for _, err := os.ReadFile(filepath.Join(dir, "go.mod")); err != nil && len(dir) > 1; {
println(dir)
dir = filepath.Dir(dir)
_, err = os.ReadFile(filepath.Join(dir, "go.mod"))
}
if len(dir) < 2 {
panic("No go.mod found")
}
return dir
}