-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.go
66 lines (59 loc) · 1.16 KB
/
util.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
56
57
58
59
60
61
62
63
64
65
66
package inertia
import (
"strings"
)
func inArray(needle string, heyStack []string) bool {
for _, v := range heyStack {
if needle == v {
return true
}
}
return false
}
func mergeProps(props ...map[string]interface{}) map[string]interface{} {
merged := map[string]interface{}{}
for _, a := range props {
for k, v := range a {
merged[k] = v
}
}
return merged
}
func splitAndRemoveEmpty(s string, sep string) []string {
var ret []string
if s == "" {
return ret
}
for _, str := range strings.Split(s, sep) {
if str != "" {
ret = append(ret, str)
}
}
return ret
}
// evaluateProps evaluates the given props and update it.
func evaluateProps(values map[string]interface{}) error {
for k, v := range values {
switch converted := v.(type) {
case map[string]interface{}:
if err := evaluateProps(converted); err != nil {
return err
}
case *LazyProp:
vv, err := converted.callback()
if err != nil {
return err
}
values[k] = vv
case func() (interface{}, error):
vv, err := converted()
if err != nil {
return err
}
values[k] = vv
case func() interface{}:
values[k] = converted()
}
}
return nil
}