-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
58 lines (48 loc) · 1.18 KB
/
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
package connectorName
import "errors"
const (
GlobalConfigParam = "global_config"
SourceConfigParam = "source_config"
DestinationConfigParam = "destination_config"
)
var Required = []string{GlobalConfigParam}
var (
ErrEmptyConfig = errors.New("missing or empty config")
)
type Config struct {
globalConfigParam 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{globalConfigParam: cfg[GlobalConfigParam]},
sourceConfigParam: cfg[SourceConfigParam],
}, nil
}
func ParseDestinationConfig(cfg map[string]string) (DestinationConfig, error) {
err := checkEmpty(cfg)
if err != nil {
return DestinationConfig{}, err
}
return DestinationConfig{
Config: Config{globalConfigParam: cfg[GlobalConfigParam]},
destinationConfigParam: cfg[DestinationConfigParam],
}, nil
}
func checkEmpty(cfg map[string]string) error {
if len(cfg) == 0 {
return ErrEmptyConfig
}
return nil
}