-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftagsdefs.go
114 lines (98 loc) · 2.46 KB
/
conftagsdefs.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package conftagz
import "strings"
// func NewConfTagOptsMap (opts []ConfTagOpts) map[string]string {
func processConfTagOptsValues(conftags string) map[string]string {
confMap := make(map[string]string)
if len(conftags) > 0 {
conftagops := strings.Split(conftags, ",")
for _, conftagop := range conftagops {
pair := strings.SplitN(strings.TrimSpace(conftagop), "=", 2)
if len(pair) == 2 {
confMap[pair[0]] = pair[1]
} else {
confMap[pair[0]] = ""
}
}
}
return confMap
}
func skipField(confops map[string]string) bool {
if _, ok := confops["skip"]; ok {
// skip this field
return true
}
return false
}
// if the value is nil, run the default logic anyway
// even if skipnil is set
func nilDefault(confops map[string]string) bool {
if _, ok := confops["nildefault"]; ok {
// skip this field
return true
}
return false
}
func skipIfNil(confops map[string]string) bool {
if _, ok := confops["skipnil"]; ok {
// skip this field
return true
}
return false
}
func skipIfZero(confops map[string]string) bool {
if _, ok := confops["skipzero"]; ok {
return true
}
return false
}
// true if the env var must exist, returns an error if it does not
func mustEnv(confops map[string]string) bool { // nolint:golint,unused
if _, ok := confops["mustenv"]; ok {
return true
}
return false
}
// The env var processing is entirely skipped
// for this field. Useful if you don't want a blank struct created
// while looking for env vars
func envSkip(confops map[string]string) bool {
if _, ok := confops["envskip"]; ok {
return true
}
return false
}
func defaultSkip(confops map[string]string) bool {
if _, ok := confops["defaultskip"]; ok {
return true
}
return false
}
func testSkip(confops map[string]string) bool {
if _, ok := confops["testskip"]; ok {
return true
}
return false
}
// true if the envvar should always replace a value
// if the env var exists
func preferEnv(confops map[string]string) bool { // nolint:golint,unused
if _, ok := confops["preferenv"]; ok {
return true
}
return false
}
// if true then env var is only used if the field has the zero value
func backupEnv(confops map[string]string) bool { // nolint:golint,unused
if _, ok := confops["backupenv"]; ok {
return true
}
return false
}
// if true, then this test will only warn and never
// cause an error to return
func testWarn(confops map[string]string) bool { // nolint:golint,unused
if _, ok := confops["testwarn"]; ok {
return true
}
return false
}