Skip to content

Commit

Permalink
Merge pull request #9 from simplifi/update-config
Browse files Browse the repository at this point in the history
Reduce complexity of config structure
  • Loading branch information
cjonesy authored Sep 13, 2024
2 parents abf6f3f + 66a0f9e commit d4360ba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 41 deletions.
8 changes: 5 additions & 3 deletions examples/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
name: example

watcher:
time:
type: time
config:
poll_seconds: 1

executioner:
log:
tag: example
type: log
config:
tag: example
36 changes: 0 additions & 36 deletions internal/goverseer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ type WatcherConfig struct {
Config interface{}
}

// UnmarshalYAML implements the yaml.Unmarshaler interface for WatcherConfig
// Because we want to have the type parsed from the yaml node rather than having
// to specify a watcher.type node in the config we need custom unmarshalling
func (d *WatcherConfig) UnmarshalYAML(value *yaml.Node) error {
var raw map[string]interface{}
if err := value.Decode(&raw); err != nil {
return err
}

for k, v := range raw {
d.Type = k
d.Config = v
break
}

return nil
}

// ExecutionerConfig is a custom type that handles dynamic unmarshalling
type ExecutionerConfig struct {
// Type is the type of executioner
Expand All @@ -44,24 +26,6 @@ type ExecutionerConfig struct {
Config interface{}
}

// UnmarshalYAML implements the yaml.Unmarshaler interface for WatcherConfig
// Because we want to have the type parsed from the yaml node rather than having
// to specify a watcher.type node in the config we need custom unmarshalling
func (d *ExecutionerConfig) UnmarshalYAML(value *yaml.Node) error {
var raw map[string]interface{}
if err := value.Decode(&raw); err != nil {
return err
}

for k, v := range raw {
d.Type = k
d.Config = v
break
}

return nil
}

// Config is the configuration for a watcher and executioner
type Config struct {
// Name is the name of the configuration, this will show up in logs
Expand Down
6 changes: 4 additions & 2 deletions internal/goverseer/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const (
testConfigWatcherToLog = `
name: WatcherToLog
watcher:
time:
type: time
config:
poll_seconds: 1
executioner:
log:
type: log
config:
tag: test
`
)
Expand Down

0 comments on commit d4360ba

Please sign in to comment.