1 Star 0 Fork 0

mwdworks/packr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
packr.go 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
Yonghwan SO 提交于 2021-10-30 20:53 . moved v2 files from v2/ to /
package packr
import (
"fmt"
"github.com/gobuffalo/packr/v2/file/resolver"
"github.com/gobuffalo/packr/v2/jam/parser"
"github.com/gobuffalo/packr/v2/plog"
"github.com/markbates/safe"
)
var boxes = &boxMap{}
var _ = safe.Run(func() {
p, err := parser.NewFromRoots([]string{}, nil)
if err != nil {
plog.Logger.Error(err)
return
}
boxes, err := p.Run()
if err != nil {
plog.Logger.Error(err)
return
}
for _, box := range boxes {
b := construct(box.Name, box.AbsPath)
_, err = placeBox(b)
if err != nil {
plog.Logger.Error(err)
return
}
}
})
func findBox(name string) (*Box, error) {
key := resolver.Key(name)
plog.Debug("packr", "findBox", "name", name, "key", key)
b, ok := boxes.Load(key)
if !ok {
plog.Debug("packr", "findBox", "name", name, "key", key, "found", ok)
return nil, fmt.Errorf("could not find box %s", name)
}
plog.Debug(b, "found", "box", b)
return b, nil
}
func placeBox(b *Box) (*Box, error) {
key := resolver.Key(b.Name)
eb, _ := boxes.LoadOrStore(key, b)
plog.Debug("packr", "placeBox", "name", eb.Name, "path", eb.Path, "resolution directory", eb.ResolutionDir)
return eb, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mwdworks/packr.git
git@gitee.com:mwdworks/packr.git
mwdworks
packr
packr
master

搜索帮助