-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (40 loc) · 940 Bytes
/
config.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
package jsont
const (
_defIndexLeaves = true
_defValidate = true
)
// Option is a configuration option of the JSONTransformer and forms part of the functional options pattern
// described, e.g., in the Uber Go Style Guide: https://github.com/uber-go/guide/blob/master/style.md#functional-options
type Option interface {
apply(opts *options)
}
type options struct {
indexLeaves bool
validate bool
}
type (
indexLeavesOption bool
validateOption bool
)
func (i indexLeavesOption) apply(opts *options) {
opts.indexLeaves = true
}
func (v validateOption) apply(opts *options) {
opts.validate = true
}
func withIndexLeaves(i bool) Option {
return indexLeavesOption(i)
}
func withValidate(v bool) Option {
return validateOption(v)
}
func newOptions(opts ...Option) options {
opt := options{
indexLeaves: _defIndexLeaves,
validate: _defValidate,
}
for _, o := range opts {
o.apply(&opt)
}
return opt
}