2018-04-22 09:28:18 +00:00
|
|
|
// 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: ")
|
2018-04-22 09:31:15 +00:00
|
|
|
for k, v := range data {
|
2018-04-22 09:28:18 +00:00
|
|
|
fmt.Printf("%s : %v\n", k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func webhookHandleMessage(m *Message) {
|
|
|
|
}
|