-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.go
48 lines (38 loc) · 820 Bytes
/
builder.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 configurationmanager
import (
"github.com/andreasisnes/go-configuration-manager/modules"
)
type Builder interface {
Add(module modules.Module) Builder
Clear()
Modules() []modules.Module
Build() Configuration
}
type builder struct {
modules []modules.Module
options *Options
}
func New(options *Options) Builder {
if options == nil {
options = NewDefaultOptions()
}
return &builder{
modules: []modules.Module{},
options: options,
}
}
func (b *builder) Add(module modules.Module) Builder {
if module != nil {
b.modules = append(b.modules, module)
}
return b
}
func (b *builder) Clear() {
b.modules = []modules.Module{}
}
func (b *builder) Modules() []modules.Module {
return b.modules
}
func (b *builder) Build() Configuration {
return newConfiguration(b.options, b.Modules())
}