I am trying to write a Go program to walk down a directory and find certain file and store that information in a Map. Here is what I have so far. I am not sure how to pass the Map to the visit function since it's a callback function.
..
type MyFile struct {
Name string
FilePath string
FileMD5Hash [16]byte
}
func visit(path string, f os.FileInfo, err error) error {
fileName := f.Name()
if !f.IsDir() && strings.Contains(strings.ToLower(fileName), "myfile") {
df := parseFile(path)
fmt.Printf("Visited: %s [%x], %s, %s
", df.FilePath)
}
return nil
}
func parseFile(path string)...
func check(e error) ...
func WalkDir(path string) {
err := filepath.Walk(path, visit)
fmt.Printf("filepath.Walk() returned %v
", err)
}