examples: pretty print JSON in webhook
This commit is contained in:
parent
4ac976c7e6
commit
44bde96447
|
@ -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())
|
||||
}))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue