From 91e02c329d1b8bd27040cf5098146bc4a70128aa Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 25 May 2019 14:09:02 -0700 Subject: [PATCH] dump the JSON body Signed-off-by: Jeff Carr --- emaild/alfonso.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/emaild/alfonso.go b/emaild/alfonso.go index 86a2635..4e6b6c4 100644 --- a/emaild/alfonso.go +++ b/emaild/alfonso.go @@ -3,6 +3,7 @@ package main import "fmt" import "log" import "net/http" +import "io/ioutil" import "github.com/davecgh/go-spew/spew" @@ -12,6 +13,15 @@ func handler(w http.ResponseWriter, r *http.Request) { log.Printf("handler: fucking unknown path") } +func main() { + log.Println("listen on :9000") + + http.HandleFunc("/", handler) + http.HandleFunc("/email", handler2) + + http.ListenAndServe(":9000", nil) +} + func handler2(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") @@ -42,13 +52,14 @@ func handler2(w http.ResponseWriter, r *http.Request) { log.Printf("handler2 DEFAULT Method=", r.Method) spew.Dump(r.Method) } -} - -func main() { - log.Println("listen on :9000") - - http.HandleFunc("/", handler) - http.HandleFunc("/email", handler2) - - http.ListenAndServe(":9000", nil) + log.Println("Hi there, handler2 r.URL.Path =", r.URL.Path[1:]) + log.Println("Hi there, handler2 r.URL.Path =", r.URL.Path) + log.Println("Hi there, handler2 r.URL =", r.URL) + log.Println("Hi there, handler2 r =", r) + log.Println("Hi there, handler2 r.Body =", r.Body) + + body, err := ioutil.ReadAll(r.Body) + j := string(body) + log.Println("body =", j) + log.Println("err =", err) }