-
-
Save imranansari/909049647e89c9ebfc647a159fb9a2d3 to your computer and use it in GitHub Desktop.
filepath.walk go routine generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"path/filepath" | |
"fmt" | |
"os" | |
) | |
func main(){ | |
location := "../gocode/" | |
chann := GoWalk(location) | |
for msg := range chann { | |
fmt.Println(msg) | |
} | |
return | |
} | |
func GoWalk(location string) (chan string) { | |
chann := make(chan string) | |
go func(){ | |
filepath.Walk(location, func(path string, _ os.FileInfo, _ error)(err error){ | |
chann <- path | |
return | |
}) | |
defer close(chann) | |
}() | |
return chann | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment