package main
import (
"encoding/json"
"log"
"net/http"
)
type t struct {
Letter string
}
func page(w http.ResponseWriter, r *http.Request) {
log.Printf("r: %v\n", r)
if r.Method == "POST" {
dec := json.NewDecoder(r.Body)
v := &t{}
e := dec.Decode(v)
if e != nil {
log.Println(e)
}
log.Printf("v: %#v\n", v)
}
http.ServeFile(w, r, "page.html")
}
func main() {
http.HandleFunc("/", page)
log.Fatal(http.ListenAndServe(":8082", nil))
}
2015/09/28 11:50:52 r: &{GET / HTTP/1.1 1 1 map[Cache-Control:[max-age=0] Accept:[text/html,applicat
ion/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8] User-Agent:[Mozilla/5.0 (Windows NT 6.1; W
OW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36] Https:[1] Accept-Enc
oding:[gzip, deflate, sdch] Accept-Language:[en-US,en;q=0.8,pt;q=0.6] Connection:[keep-alive]] 0x8b0
a10 0 [] false localhost:8082 map[] map[] <nil> map[] [::1]:53593 / <nil> <nil>}
2015/09/28 11:51:20 r: &{POST / HTTP/1.1 1 1 map[Content-Type:[application/x-www-form-urlencoded] Ca
che-Control:[max-age=0] User-Agent:[Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, l
ike Gecko) Chrome/44.0.2403.89 Safari/537.36] Https:[1] Accept:[text/html,application/xhtml+xml,appl
2/] Accept-Encoding:[gzip, deflate] Accept-Language:[en-US,en;q=0.8,pt;q=0.6] Connection:[keep-alive
] Content-Length:[8]] 0xc0821b1bc0 8 [] false localhost:8082 map[] map[] <nil> map[] [::1]:53593 / <
nil> <nil>}
2015/09/28 12:21:28 r.Body: &{0xc082204c00 <nil> <nil> false true {0 0} false false false}
2015/09/28 12:21:28 invalid character 'L' looking for beginning of value
2015/09/28 12:21:28 v: &main.t{Letter:""}