-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (44 loc) · 952 Bytes
/
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
package benthos
import "errors"
const (
BenthosYaml = "benthos.yaml"
)
var Required = []string{BenthosYaml}
var (
ErrEmptyConfig = errors.New("missing or empty config")
)
type Config struct {
benthosYaml string
}
type SourceConfig struct {
Config
sourceConfigParam string
}
type DestinationConfig struct {
Config
destinationConfigParam string
}
func ParseSourceConfig(cfg map[string]string) (SourceConfig, error) {
err := checkEmpty(cfg)
if err != nil {
return SourceConfig{}, err
}
return SourceConfig{
Config: Config{benthosYaml: cfg[BenthosYaml]},
}, nil
}
func ParseDestinationConfig(cfg map[string]string) (DestinationConfig, error) {
err := checkEmpty(cfg)
if err != nil {
return DestinationConfig{}, err
}
return DestinationConfig{
Config: Config{benthosYaml: cfg[BenthosYaml]},
}, nil
}
func checkEmpty(cfg map[string]string) error {
if cfg == nil || len(cfg) == 0 {
return ErrEmptyConfig
}
return nil
}