-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
54 lines (45 loc) · 1.44 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
49
50
51
52
53
54
package protoconf
// Option is config option.
type Option func(*options)
// Provider represents a configuration provider. Providers can
// read configuration from a source (file, HTTP etc.)
type Provider interface {
// ReadBytes Read returns the entire configuration as raw []bytes to be parsed.
// with a Parser.
ReadBytes() ([]byte, error)
// Read returns the parsed configuration as a nested map[string]interface{}.
// It is important to note that the string keys should not be flat delimited
// keys like `parent.child.key`, but nested like `{parent: {child: {key: 1}}}`.
Read() (map[string]interface{}, error)
}
// Parser represents a configuration format parser.
type Parser interface {
Unmarshal(data []byte) (map[string]interface{}, error)
}
// Transformer transforms the configuration values.
type Transformer interface {
Transform(values map[string]interface{}) (map[string]interface{}, error)
}
type options struct {
provider Provider
parser Parser
transformers []Transformer
}
// WithProvider sets the configuration provider.
func WithProvider(p Provider) Option {
return func(o *options) {
o.provider = p
}
}
// WithParser sets the configuration parser.
func WithParser(p Parser) Option {
return func(o *options) {
o.parser = p
}
}
// WithTransformers sets the configuration transformers.
func WithTransformers(t ...Transformer) Option {
return func(o *options) {
o.transformers = append(o.transformers, t...)
}
}