forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
67 lines (59 loc) · 2.3 KB
/
doc.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
/* Overrider provides an API for overriding and reading redacted values for a configuration object.
The configuration object provided is expected to have two levels of nested structs.
The top level struct should have fields called "sections".
These fields may either be a struct or a slice of structs.
As such a section consists of a list of elements.
In the case where the field is a struct and not a slice, the section list always contains one element.
Further nested levels may exist but Overrider will not interact with them directly.
If a nested field is a struct, then github.com/mitchellh/mapstructure will be used to decode the map into the struct.
In order for a section to be overridden an `override` struct tag must be present.
The `override` tag defines a name for the section and option.
Struct tags can be used to mark options as redacted by adding a `<name>,redact` to the end of the `override` tag value.
Example:
type SectionAConfig struct {
Option string `override:"option"`
Password string `override:"password,redact"`
}
type SectionBConfig struct {
ID string `override:"id"`
Option string `override:"option"`
}
type Config struct {
SectionA SectionAConfig `override:"section-a"`
SectionB []SectionBConfig `override:"section-b,element-key=id"`
IgnoredSection IgnoredConfig
IgnoredField string
}
type IgnoredConfig struct {
// contains anything ...
}
// Setup
c := Config{
SectionA: SectionAConfig{
Option: "option value",
Password: "secret",
},
SectionB: []SectionBConfig{
{
ID: "id0",
Option: "option value 0",
},
{
ID: "id1",
Option: "option value 1",
},
},
IgnoredSection: IgnoredConfig{},
IgnoredField: "this value is ignored",
}
o := override.New(c)
// Read redacted section values
redacted, err := o.Sections()
// Override options for a section
newElement, err := o.Override(Override{
Section: "section-b",
Element: "id1", // Element may be empty when overriding a section which is not a list.
Options: map[string]interface{}{"option": "overridden option value"},
})
*/
package override