aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorEthel Morgan <eth@ethulhu.co.uk>2020-07-07 20:53:52 +0100
committerEthel Morgan <eth@ethulhu.co.uk>2020-07-07 20:53:52 +0100
commitb659e33bb5798311c3f726c37a041ab2f94f4260 (patch)
tree22e050addd5d370c9219756d175ac3a791b5e5c9 /cmd
parent7cd8becb29c96a06f0c1b0cfb623ed5e98911613 (diff)
rename "actions" to "rules" and "outputs" to "actions"
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dispatch/main.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/cmd/dispatch/main.go b/cmd/dispatch/main.go
index 53aec92..032797d 100644
--- a/cmd/dispatch/main.go
+++ b/cmd/dispatch/main.go
@@ -72,10 +72,12 @@ func triggerAction(config *config.Config) http.HandlerFunc {
ctx := r.Context()
found := false
- for _, actionConfig := range config.Actions {
- if matchAction(actionConfig, r) {
+ for _, rule := range config.RulesByName {
+ if matchTriggers(rule.Triggers, r) {
found = true
- runAction(ctx, actionConfig)
+ for _, action := range rule.Actions {
+ runAction(ctx, action)
+ }
}
}
if !found {
@@ -85,8 +87,8 @@ func triggerAction(config *config.Config) http.HandlerFunc {
}
}
-func matchAction(action config.Action, r *http.Request) bool {
- for _, trigger := range action.Triggers {
+func matchTriggers(triggers []config.Trigger, r *http.Request) bool {
+ for _, trigger := range triggers {
if trigger.URL.Path != r.URL.Path {
return false
}
@@ -105,16 +107,13 @@ func matchAction(action config.Action, r *http.Request) bool {
func runAction(ctx context.Context, action config.Action) {
log, _ := logger.FromContext(ctx)
- for _, output := range action.Outputs {
- if output.Kind != config.HTTPOutput {
- log.Warning("only supports HTTP for now")
- continue
- }
+ if action.Kind != config.HTTPAction {
+ log.Warning("only supports HTTP for now")
+ }
- if _, err := http.PostForm(output.URL.String(), output.FormValues); err != nil {
- log.WithError(err).Error("could not POST form")
- continue
- }
- log.Info("POSTed to URL")
+ if _, err := http.PostForm(action.URL.String(), action.FormValues); err != nil {
+ log.WithError(err).Error("could not POST form")
+ return
}
+ log.Info("POSTed to URL")
}