代码拉取完成,页面将自动刷新
package packr
import (
"sort"
"strings"
"github.com/gobuffalo/packd"
"github.com/gobuffalo/packr/v2/file"
"github.com/gobuffalo/packr/v2/file/resolver"
"github.com/gobuffalo/packr/v2/plog"
)
// WalkFunc is used to walk a box
type WalkFunc = packd.WalkFunc
// Walk will traverse the box and call the WalkFunc for each file in the box/folder.
func (b *Box) Walk(wf WalkFunc) error {
m := map[string]file.File{}
dr := b.DefaultResolver
if dr == nil {
cd := resolver.OsPath(b.ResolutionDir)
dr = &resolver.Disk{Root: cd}
}
if fm, ok := dr.(file.FileMappable); ok {
for n, f := range fm.FileMap() {
m[n] = f
}
}
var err error
b.resolvers.Range(func(n string, r resolver.Resolver) bool {
var f file.File
f, err = r.Resolve("", n)
if err != nil {
return false
}
keep := true
for k := range m {
if strings.EqualFold(k, n) {
keep = false
}
}
if keep {
m[n] = f
}
return true
})
if err != nil {
return err
}
var keys = make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
osPath := resolver.OsPath(k)
plog.Debug(b, "Walk", "path", k, "osPath", osPath)
if err := wf(osPath, m[k]); err != nil {
return err
}
}
return nil
}
// WalkPrefix will call box.Walk and call the WalkFunc when it finds paths that have a matching prefix
func (b *Box) WalkPrefix(prefix string, wf WalkFunc) error {
ipref := resolver.OsPath(prefix)
return b.Walk(func(path string, f File) error {
ipath := resolver.OsPath(path)
if strings.HasPrefix(ipath, ipref) {
if err := wf(path, f); err != nil {
return err
}
}
return nil
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。