Skip to content

Instantly share code, notes, and snippets.

@uolter
Created March 13, 2015 13:00
Show Gist options
  • Save uolter/1df07712954428ed6397 to your computer and use it in GitHub Desktop.
Save uolter/1df07712954428ed6397 to your computer and use it in GitHub Desktop.
Dump http post with json
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type test_struct struct {
Test string
}
func parse_json(rw http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err == nil {
log.Println("---> Body")
log.Println(string(body))
} else {
log.Println(err)
}
req.ParseForm()
log.Println(req.Form)
var t test_struct
for key, _ := range req.Form {
log.Println(key)
//LOG: {"test": "that"}
err := json.Unmarshal([]byte(key), &t)
if err != nil {
log.Println(err.Error())
}
}
//LOG: that
log.Println(t.Test)
}
func main() {
http.HandleFunc("/create_project", parse_json)
log.Fatal(http.ListenAndServe(":9999", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment