diff options
author | Ethel Morgan <eth@ethulhu.co.uk> | 2020-07-07 20:53:52 +0100 |
---|---|---|
committer | Ethel Morgan <eth@ethulhu.co.uk> | 2020-07-07 20:53:52 +0100 |
commit | b659e33bb5798311c3f726c37a041ab2f94f4260 (patch) | |
tree | 22e050addd5d370c9219756d175ac3a791b5e5c9 /config | |
parent | 7cd8becb29c96a06f0c1b0cfb623ed5e98911613 (diff) |
rename "actions" to "rules" and "outputs" to "actions"
Diffstat (limited to '')
-rw-r--r-- | config/config.go | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/config/config.go b/config/config.go index 38bf73c..01f6b82 100644 --- a/config/config.go +++ b/config/config.go @@ -12,10 +12,10 @@ import ( ) type ( - Action struct { + Rule struct { Name string Triggers []Trigger - Outputs []Output + Actions []Action } Trigger struct { @@ -23,9 +23,9 @@ type ( FormValues url.Values } - OutputKind int - Output struct { - Kind OutputKind + ActionKind int + Action struct { + Kind ActionKind Name string URL *url.URL @@ -36,22 +36,22 @@ type ( } Config struct { - Actions map[string]Action + RulesByName map[string]Rule } config struct { - Actions map[string]struct { + Rules map[string]struct { Triggers []struct { URL uurl `json:"url"` FormValues map[string]string `json:"formValues"` } `json:"triggers"` - Outputs []struct { + Actions []struct { URL uurl `json:"url"` FormValues map[string]string `json:"formValues"` MQTT uurl `json:"mqtt"` Value string `json:"value"` - } `json:"outputs"` - } `json:"actions"` + } `json:"actions"` + } `json:"rules"` } uurl struct { @@ -60,8 +60,8 @@ type ( ) const ( - HTTPOutput OutputKind = iota - MQTTOutput + HTTPAction ActionKind = iota + MQTTAction ) func ParseFile(path string) (*Config, error) { @@ -80,11 +80,11 @@ func ParseFile(path string) (*Config, error) { func configFromConfig(raw config) (*Config, error) { c := &Config{ - Actions: map[string]Action{}, + RulesByName: map[string]Rule{}, } - for k, v := range raw.Actions { - action := Action{ + for k, v := range raw.Rules { + rule := Rule{ Name: k, } @@ -93,27 +93,27 @@ func configFromConfig(raw config) (*Config, error) { URL: rawTrigger.URL.URL, FormValues: urlValuesFromRawValues(rawTrigger.FormValues), } - action.Triggers = append(action.Triggers, trigger) + rule.Triggers = append(rule.Triggers, trigger) } - for _, rawOutput := range v.Outputs { - output := Output{ - URL: rawOutput.URL.URL, - FormValues: urlValuesFromRawValues(rawOutput.FormValues), - MQTT: rawOutput.MQTT.URL, - Value: rawOutput.Value, + for _, rawAction := range v.Actions { + action := Action{ + URL: rawAction.URL.URL, + FormValues: urlValuesFromRawValues(rawAction.FormValues), + MQTT: rawAction.MQTT.URL, + Value: rawAction.Value, } switch { - case output.URL != nil && output.MQTT == nil: - output.Kind = HTTPOutput - case output.URL == nil && output.MQTT != nil: - output.Kind = MQTTOutput + case action.URL != nil && action.MQTT == nil: + action.Kind = HTTPAction + case action.URL == nil && action.MQTT != nil: + action.Kind = MQTTAction default: - return nil, errors.New("outputs must be URL xor MQTT") + return nil, errors.New("actions must be URL xor MQTT") } - action.Outputs = append(action.Outputs, output) + rule.Actions = append(rule.Actions, action) } - c.Actions[k] = action + c.RulesByName[k] = rule } |