/
map_config.go
61 lines (49 loc) · 1.42 KB
/
map_config.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
55
56
57
58
59
60
61
package index
import (
"errors"
"fmt"
"github.com/rodb-io/rodb/pkg/input"
"github.com/sirupsen/logrus"
)
type MapConfig struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Input string `yaml:"input"`
Properties []string `yaml:"properties"`
Logger *logrus.Entry
}
func (config *MapConfig) Validate(inputs map[string]input.Config, log *logrus.Entry) error {
config.Logger = log
if config.Name == "" {
return errors.New("map.name is required")
}
_, inputExists := inputs[config.Input]
if !inputExists {
return fmt.Errorf("map.input: Input '%v' not found in inputs list.", config.Input)
}
alreadyExistingProperties := make(map[string]bool)
for _, propertyName := range config.Properties {
if _, alreadyExists := alreadyExistingProperties[propertyName]; alreadyExists {
return fmt.Errorf("map.properties: Duplicate property '%v' in array.", propertyName)
}
alreadyExistingProperties[propertyName] = true
}
// The properties will be validated at runtime
return nil
}
func (config *MapConfig) GetName() string {
return config.Name
}
func (config *MapConfig) DoesHandleProperty(property string) bool {
isHandled := false
for _, handledProperty := range config.Properties {
if property == handledProperty {
isHandled = true
break
}
}
return isHandled
}
func (config *MapConfig) DoesHandleInput(input input.Config) bool {
return input.GetName() == config.Input
}