Use fastwalk for parallel directory traversal
masterThe fastwalk package provides a high-performance, parallel version of filepath.WalkDir. It uses multiple goroutines to concurrently stat the filesystem and execute the callback function, making it significantly faster than the standard library on macOS, Linux, and Windows.
Important Requirement: Because fastwalk executes the callback function concurrently, your walkFn (the function that processes each file/directory) must be safe for concurrent use (thread-safe).
// Example of basic usage
conf := &fastwalk.Config{
Follow: true, // Set to true to follow symbolic links
}
walkFn := func(path string, d fs.DirEntry, err error) error {
// Your logic here.
// MUST BE THREAD-SAFE
fmt.Println(path)
return nil
}
err := fastwalk.Walk(conf, "/path/to/root", walkFn)