-
Notifications
You must be signed in to change notification settings - Fork 791
/
config_set.go
37 lines (30 loc) · 978 Bytes
/
config_set.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
package manager
import (
"github.com/Jeffail/benthos/v3/lib/stream"
yaml "gopkg.in/yaml.v3"
)
//------------------------------------------------------------------------------
// ConfigSet is a map of stream configurations mapped by ID, which can be YAML
// parsed without losing default values inside the stream configs.
type ConfigSet map[string]stream.Config
// UnmarshalYAML ensures that when parsing configs that are in a map or slice
// the default values are still applied.
func (c ConfigSet) UnmarshalYAML(unmarshal func(interface{}) error) error {
tmpSet := map[string]interface{}{}
if err := unmarshal(&tmpSet); err != nil {
return err
}
for k, v := range tmpSet {
conf := stream.NewConfig()
confBytes, err := yaml.Marshal(v)
if err != nil {
return err
}
if err = yaml.Unmarshal(confBytes, &conf); err != nil {
return err
}
c[k] = conf
}
return nil
}
//------------------------------------------------------------------------------