From 63cf13e93d0fcf00d0037474343f1d834a4b114a Mon Sep 17 00:00:00 2001 From: Valentin Fedoskin Date: Sat, 23 May 2020 17:50:33 +0200 Subject: [PATCH] unmarshal json --- pkg/notifier/events.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/notifier/events.go b/pkg/notifier/events.go index 4870c28..b51c45e 100644 --- a/pkg/notifier/events.go +++ b/pkg/notifier/events.go @@ -1,15 +1,20 @@ package notifier import ( + "encoding/json" "github.com/sirupsen/logrus" "io/ioutil" "net/http" ) func handleEventsRequest(w http.ResponseWriter, r *http.Request) { - event, err := ioutil.ReadAll(r.Body) + data, err := ioutil.ReadAll(r.Body) if err != nil { logrus.WithError(err).Info("failed to read request body") } - logrus.WithField("event", string(event)).Info("received event") + event := make(map[string]interface{}) + if err := json.Unmarshal(data, &event); err != nil { + logrus.WithError(err).WithField("data", string(data)).Error("failed to unmarshal json") + } + logrus.WithField("event", event).Info("received event") }