blob: 01fa6dd8882ba9f5928b739f4e2329d9304c6bd7 (
plain)
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
|
package config
import "strconv"
// Flag represents a nullable boolean value that is considered null until
// either parsed from YAML or merged in from another Flag value.
//
type Flag struct {
True bool
set bool
}
// UnmarshalJSON implements json.Unmarshaler to parse the underlying boolean
// value and detect that the Flag should no longer be considered null.
//
func (flag *Flag) UnmarshalJSON(unmarshal []byte) error {
var err error
flag.True, err = strconv.ParseBool(string(unmarshal))
if err != nil {
return err
}
flag.set = true
return nil
}
// Merge takes another flag and, if set, merged its boolean value into this
// one.
//
func (flag *Flag) Merge(flag2 Flag) {
if flag2.set {
flag.True = flag2.True
flag.set = true
}
}
|