-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.go
69 lines (59 loc) · 1.44 KB
/
utils.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
67
68
69
package denada
import "github.com/bitly/go-simplejson"
func getString(v *simplejson.Json) (string, bool) {
str, err := v.String()
return str, err == nil
}
func getStringArray(v *simplejson.Json) ([]string, bool) {
str, err := v.StringArray()
return str, err == nil
}
/*
A special utility function to quickly get the value (if it exists) of constructs
like this:
fmu SomeName {
parameter := "Contents";
}
*/
func GetStringParameter(app *Element, key string) (string, bool) {
e := app.Contents.Declarations().FirstNamed(key)
if e == nil {
return "", false
}
return getString(e.Value)
}
func GetStringValue(app *Element) (string, bool) {
val := app.Value
if val == nil {
return "", false
}
return getString(val)
}
func GetStringModification(app *Element, key string) (string, bool) {
val, exists := app.Modifications[key]
if !exists {
return "", false
}
return getString(val)
}
func GetStringArrayParameter(app *Element, key string) ([]string, bool) {
e := app.Contents.Declarations().FirstNamed(key)
if e == nil {
return []string{}, false
}
return getStringArray(e.Value)
}
func GetStringArrayValue(app *Element) ([]string, bool) {
val := app.Value
if val == nil {
return []string{}, false
}
return getStringArray(val)
}
func GetStringArrayModification(app *Element, key string) ([]string, bool) {
val, exists := app.Modifications[key]
if !exists {
return []string{}, false
}
return getStringArray(val)
}