forked from gobuffalo/packr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packr.go
55 lines (46 loc) · 1.15 KB
/
packr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package packr
import (
"github.com/gobuffalo/packr/v2/file/resolver"
"github.com/gobuffalo/packr/v2/jam/parser"
"github.com/gobuffalo/packr/v2/plog"
"github.com/markbates/safe"
"github.com/pkg/errors"
)
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, errors.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
}