Skip to content

Instantly share code, notes, and snippets.

@sethamclean
Created March 10, 2014 22:21
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sethamclean/9475737 to your computer and use it in GitHub Desktop.
Save sethamclean/9475737 to your computer and use it in GitHub Desktop.
filepath.walk go routine generator
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