From 8ef027800c3852db3002cbf6776f8953265df922 Mon Sep 17 00:00:00 2001 From: an Date: Sun, 22 Apr 2018 11:28:18 +0200 Subject: [PATCH] added modules/webhoook.go --- modules/webhook.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 modules/webhook.go diff --git a/modules/webhook.go b/modules/webhook.go new file mode 100644 index 0000000..25594a7 --- /dev/null +++ b/modules/webhook.go @@ -0,0 +1,39 @@ +// vi:ts=4:sts=4:sw=4:noet:tw=72 + +package modules + +import ( + "encoding/json" + "fmt" + "log" + "net/http" + + "git.dnix.de/an/xlog" +) + +func init() { + MsgFuncs["webhook"] = webhookHandleMessage + RunFuncs["webhook"] = webhookRun +} + +func webhookRun() { + xlog.Info("webhook listener started") + http.HandleFunc("/webhook", webhookHandleHTTP) + log.Fatal(http.ListenAndServe(":8080", nil)) +} + +func webhookHandleHTTP(w http.ResponseWriter, r *http.Request) { + data := make(map[string]interface{}) + err := json.NewDecoder(r.Body).Decode(&data) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + fmt.Println("got webhook payload: ") + for k, v := range webhookData { + fmt.Printf("%s : %v\n", k, v) + } +} + +func webhookHandleMessage(m *Message) { +}