diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/dispatch/main.go | 29 |
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") } |