From 44bde96447e0edf5ed53a7320c7fd08d6deb101b Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 5 Sep 2016 11:17:28 +0200 Subject: [PATCH] examples: pretty print JSON in webhook --- examples/webhook/echo.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/webhook/echo.go b/examples/webhook/echo.go index 26ea646a..43ccf1b4 100644 --- a/examples/webhook/echo.go +++ b/examples/webhook/echo.go @@ -1,19 +1,24 @@ package main import ( + "bytes" + "encoding/json" + "fmt" "io/ioutil" - "log" "net/http" ) func main() { http.ListenAndServe(":5001", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - log.Println("received request:", r.Header) b, err := ioutil.ReadAll(r.Body) if err != nil { panic(err) } defer r.Body.Close() - log.Println("request body:", string(b)) + var buf bytes.Buffer + if err := json.Indent(&buf, b, " >", " "); err != nil { + panic(err) + } + fmt.Println(buf.String()) })) }