aboutsummaryrefslogtreecommitdiff
path: root/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go58
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
}