forked from redpanda-data/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_switch.go
58 lines (47 loc) · 1.55 KB
/
config_switch.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 processor
import (
"encoding/json"
)
// SwitchCaseConfig contains a condition, processors and other fields for an
// individual case in the Switch processor.
type SwitchCaseConfig struct {
Check string `json:"check" yaml:"check"`
Processors []Config `json:"processors" yaml:"processors"`
Fallthrough bool `json:"fallthrough" yaml:"fallthrough"`
}
// NewSwitchCaseConfig returns a new SwitchCaseConfig with default values.
func NewSwitchCaseConfig() SwitchCaseConfig {
return SwitchCaseConfig{
Check: "",
Processors: []Config{},
Fallthrough: false,
}
}
// UnmarshalJSON ensures that when parsing configs that are in a map or slice
// the default values are still applied.
func (s *SwitchCaseConfig) UnmarshalJSON(bytes []byte) error {
type confAlias SwitchCaseConfig
aliased := confAlias(NewSwitchCaseConfig())
if err := json.Unmarshal(bytes, &aliased); err != nil {
return err
}
*s = SwitchCaseConfig(aliased)
return nil
}
// UnmarshalYAML ensures that when parsing configs that are in a map or slice
// the default values are still applied.
func (s *SwitchCaseConfig) UnmarshalYAML(unmarshal func(any) error) error {
type confAlias SwitchCaseConfig
aliased := confAlias(NewSwitchCaseConfig())
if err := unmarshal(&aliased); err != nil {
return err
}
*s = SwitchCaseConfig(aliased)
return nil
}
// SwitchConfig is a config struct containing fields for the Switch processor.
type SwitchConfig []SwitchCaseConfig
// NewSwitchConfig returns a default SwitchConfig.
func NewSwitchConfig() SwitchConfig {
return SwitchConfig{}
}