ch8/ch8-08 #185
ch8/ch8-08
#185
Replies: 1 comment
-
Go1.16版本之后 func walkDir(dir string, wg *sync.WaitGroup, fileSizes chan<- int64) {
// ...
for _, entry := range dirents(dir) {
if entry.IsDir() {
wg.Add(1)
subdir := filepath.Join(dir, entry.Name())
walkDir(subdir, wg, fileSizes)
} else {
// 以下这种写法隐式忽略了返回的错误变量,编译器不允许!
// fileSizes <- entry.Info().Size() => 返回值是Info和err
info, _ := entry.Info()
fileSizes <- info.Size()
}
}
}
func dirents(dir string) []os.DirEntry {
entries, err := os.ReadDir(dir)
// ...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
ch8/ch8-08
中文版
https://golang-china.github.io/gopl-zh/ch8/ch8-08.html
Beta Was this translation helpful? Give feedback.
All reactions