package file import ( "os" "path/filepath" "runtime" ) var ( _, b, _, _ = runtime.Caller(0) // Root folder of this project ProjectRoot = filepath.Join(filepath.Dir(b), "..") ) // GetBasePath returns the root folder of the project func GetBasePath() 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 }