package tree import ( "os" "path/filepath" ) type RealWalker struct { path string report chan int64 } func (r *RealWalker) walkFunc(path string, info os.FileInfo, err error) error { if !info.IsDir() { switch mode := info.Mode(); { case mode.IsRegular(): r.report <- info.Size() } } return nil } func (r *RealWalker) Walk() { filepath.Walk(r.path, r.walkFunc) close(r.report) } func NewRealWalker(path string, report chan int64) *RealWalker { r := &RealWalker{path: path, report: report} return r }