Skip to content

Instantly share code, notes, and snippets.

@eyeezzi
Last active February 21, 2018 14:06
Show Gist options
  • Save eyeezzi/61cce1bb507006b961761eba6ab3304b to your computer and use it in GitHub Desktop.
Save eyeezzi/61cce1bb507006b961761eba6ab3304b to your computer and use it in GitHub Desktop.
Alternative way to read JSON body using ioutil.ReadAll()
func CreateNote(w http.ResponseWriter, r *http.Request) {
var m map[string]interface{}
body, err := ioutil.ReadAll(r.Body)
if err = json.Unmarshal(body, &m); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintln(w, "done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment