forked from choria-legacy/go-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutators.go
40 lines (31 loc) · 805 Bytes
/
mutators.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
package config
import (
"sync"
"github.com/sirupsen/logrus"
)
// Mutator is a function that can mutate the configuration
type Mutator interface {
Mutate(*Config, *logrus.Entry)
}
var mutators = []Mutator{}
var mutatorNames = []string{}
var mu = &sync.Mutex{}
// RegisterMutator registers a new configuration mutator
func RegisterMutator(name string, m Mutator) {
mu.Lock()
defer mu.Unlock()
mutators = append(mutators, m)
mutatorNames = append(mutatorNames, name)
}
// MutatorNames are the names of known configuration mutators
func MutatorNames() []string {
return mutatorNames
}
// Mutate calls all registered mutators on the given configuration
func Mutate(c *Config, log *logrus.Entry) {
mu.Lock()
defer mu.Unlock()
for _, mutator := range mutators {
mutator.Mutate(c, log)
}
}