dump the JSON body

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-25 14:09:02 -07:00
parent 7110856b18
commit 91e02c329d
1 changed files with 20 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package main
import "fmt" import "fmt"
import "log" import "log"
import "net/http" import "net/http"
import "io/ioutil"
import "github.com/davecgh/go-spew/spew" 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") 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) { func handler2(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") 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) log.Printf("handler2 DEFAULT Method=", r.Method)
spew.Dump(r.Method) spew.Dump(r.Method)
} }
} log.Println("Hi there, handler2 r.URL.Path =", r.URL.Path[1:])
log.Println("Hi there, handler2 r.URL.Path =", r.URL.Path)
func main() { log.Println("Hi there, handler2 r.URL =", r.URL)
log.Println("listen on :9000") log.Println("Hi there, handler2 r =", r)
log.Println("Hi there, handler2 r.Body =", r.Body)
http.HandleFunc("/", handler)
http.HandleFunc("/email", handler2) body, err := ioutil.ReadAll(r.Body)
j := string(body)
http.ListenAndServe(":9000", nil) log.Println("body =", j)
log.Println("err =", err)
} }