我有以下代码:
func loopThroughDirs(path string, fileInfo os.FileInfo, err error) error {
...do something with service...
return nil
}
func main() {
service, err := storage.New(client)
...
filepath.Walk(*dirName, loopThroughDirs)
}
我要解决的问题是这个,我要在service
里面 使用loopThroughDirs()
。我该怎么做呢?
PS:loopThroughDirs
内部的函数filepath.Walk()
在Go中称为回调吗?
您也可以尝试返回一个WalkFunc
函数:
func main() {
service, err := storage.New(client)
...
filepath.Walk(*dirName, getWalkFunc(service))
}
func getWalkFunc(service storage.Service) filepath.WalkFunc {
return func(path string, fileInfo os.FileInfo, err error) error {
// ...do something with service...
return nil
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句