github.com/samlitowitz/goimportcycle@v1.0.9/internal/modfile/find_go_mod_file.go (about) 1 package modfile 2 3 import ( 4 "errors" 5 "os" 6 "path/filepath" 7 ) 8 9 func FindGoModFile(path string) (string, error) { 10 _, err := os.Stat(path + "/go.mod") 11 if err == nil { 12 return path + "/go.mod", nil 13 } 14 if !errors.Is(err, os.ErrNotExist) { 15 return path + "/go.mod", nil 16 } 17 parent := filepath.Dir(path) 18 if parent == path { 19 return "", &FileNotFoundError{Name: parent + "/go.mod"} 20 } 21 return FindGoModFile(parent) 22 }