aboutsummaryrefslogtreecommitdiff
path: root/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go37
1 files changed, 20 insertions, 17 deletions
diff --git a/config/config.go b/config/config.go
index 01f6b82..347fdac 100644
--- a/config/config.go
+++ b/config/config.go
@@ -31,8 +31,9 @@ type (
URL *url.URL
FormValues url.Values
- MQTT *url.URL
- Value string
+ MQTT *url.URL
+ Value string
+ Retain bool
}
Config struct {
@@ -50,6 +51,7 @@ type (
FormValues map[string]string `json:"formValues"`
MQTT uurl `json:"mqtt"`
Value string `json:"value"`
+ Retain bool `json:"retain"`
} `json:"actions"`
} `json:"rules"`
}
@@ -89,28 +91,29 @@ func configFromConfig(raw config) (*Config, error) {
}
for _, rawTrigger := range v.Triggers {
- trigger := Trigger{
+ rule.Triggers = append(rule.Triggers, Trigger{
URL: rawTrigger.URL.URL,
FormValues: urlValuesFromRawValues(rawTrigger.FormValues),
- }
- rule.Triggers = append(rule.Triggers, trigger)
+ })
}
- for _, rawAction := range v.Actions {
- action := Action{
- URL: rawAction.URL.URL,
- FormValues: urlValuesFromRawValues(rawAction.FormValues),
- MQTT: rawAction.MQTT.URL,
- Value: rawAction.Value,
- }
+ for _, action := range v.Actions {
+ var kind ActionKind
switch {
- case action.URL != nil && action.MQTT == nil:
- action.Kind = HTTPAction
- case action.URL == nil && action.MQTT != nil:
- action.Kind = MQTTAction
+ case action.URL != uurl{} && action.MQTT == uurl{}:
+ kind = HTTPAction
+ case action.URL == uurl{} && action.MQTT != uurl{}:
+ kind = MQTTAction
default:
return nil, errors.New("actions must be URL xor MQTT")
}
- rule.Actions = append(rule.Actions, action)
+ rule.Actions = append(rule.Actions, Action{
+ Kind: kind,
+ URL: action.URL.URL,
+ FormValues: urlValuesFromRawValues(action.FormValues),
+ MQTT: action.MQTT.URL,
+ Value: action.Value,
+ Retain: action.Retain,
+ })
}
c.RulesByName[k] = rule