-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoption.go
69 lines (58 loc) · 1.23 KB
/
option.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 godiff
//ConfigOption represents an option
type ConfigOption func(config *Config)
type Options struct {
setMarker bool
shallow bool
nullifyEmpty *bool
depth int
}
func (o *Options) decDepth() {
o.depth--
}
func (o *Options) Apply(options []Option) {
for _, item := range options {
item(o)
}
}
type Option func(c *Options)
//WithTagName updated config tag
func WithTagName(name string) ConfigOption {
return func(config *Config) {
config.TagName = name
}
}
//WithTag updated config tag
func WithTag(tag *Tag) ConfigOption {
return func(config *Config) {
config.tag = tag
}
}
func WithSetMarker(f bool) Option {
return func(options *Options) {
options.setMarker = f
}
}
func WithShallow(f bool) Option {
return func(options *Options) {
options.shallow = f
}
}
//NullifyEmpty updated config option
func NullifyEmpty(flag bool) ConfigOption {
return func(options *Config) {
options.NullifyEmpty = &flag
}
}
//WithConfig updated config tag
func WithConfig(cfg *Config) ConfigOption {
return func(config *Config) {
*config = *cfg
}
}
//WithRegistry updated config with registry
func WithRegistry(registry *Registry) ConfigOption {
return func(config *Config) {
config.registry = registry
}
}