-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
48 lines (40 loc) · 1.08 KB
/
options.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
package gofig
// An Option configures gofig.
type Option interface {
apply(*Loader)
}
// An OptionFunc is an adapter allowing regular methods to act as Option's.
type OptionFunc func(*Loader)
func (fn OptionFunc) apply(c *Loader) {
fn(c)
}
// SetLogger sets logger.
func SetLogger(v Logger) Option {
return OptionFunc(func(l *Loader) {
l.logger = v
})
}
// SetKeyFormatter sets the formatter to be used for received keys from parsers.
func SetKeyFormatter(formatter Formatter) Option {
return OptionFunc(func(l *Loader) {
l.keyFormatter = formatter
})
}
// SetStructTag changes the struct tag gofig looks for on struct fields to the value provided.
func SetStructTag(t string) Option {
return OptionFunc(func(l *Loader) {
l.structTag = t
})
}
// SetEnforcePriority enable or disable parser priority enforcement.
func SetEnforcePriority(v bool) Option {
return OptionFunc(func(l *Loader) {
l.enforcePriority = v
})
}
// WithDebug enables debugging. Use SetLogger to customise the logging output.
func WithDebug() Option {
return OptionFunc(func(l *Loader) {
l.debug = true
})
}