forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
join.go
43 lines (39 loc) · 1.08 KB
/
join.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
package assets
import (
"fmt"
"sort"
)
// JoinAssetFuncs returns an asset function that delegates to each of the provided asset functions in turn.
// The functions are assumed to provide non-overlapping assets
func JoinAssetFuncs(funcs ...AssetFunc) AssetFunc {
return func(name string) ([]byte, error) {
for _, f := range funcs {
if data, err := f(name); err == nil {
return data, nil
}
}
return nil, fmt.Errorf("Asset %s not found", name)
}
}
// JoinAssetDirFuncs returns an asset dir function that delegates to the provided asset dir functions.
// The functions are assumed to provide non-overlapping assets
func JoinAssetDirFuncs(funcs ...AssetDirFunc) AssetDirFunc {
roots := []string{}
for _, f := range funcs {
if localRoots, err := f(""); err == nil {
roots = append(roots, localRoots...)
}
}
sort.Strings(roots)
return func(name string) ([]string, error) {
if name == "" {
return roots, nil
}
for _, f := range funcs {
if dirs, err := f(name); err == nil {
return dirs, nil
}
}
return nil, fmt.Errorf("Asset %s not found", name)
}
}