What's the idiomatic way, if possible, of having Go's filepath.Walk
return early?
I'm writing a function to find a nested directory of a given name. Using filepath.Walk
I can't see a way of terminating the tree-walking as soon as I find the first match.
func (*RecursiveFinder) Find(needle string, haystack string) (result string, err error) {
filepath.Walk(haystack, func(path string, fi os.FileInfo, errIn error) (errOut error) {
fmt.Println(path)
if fi.Name() == needle {
fmt.Println("Found " + path)
result = path
return nil
}
return
})
return
}