Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SeanChristopherConway/6c4371b0ba2c7f532ac4f6aa5cf4f04d to your computer and use it in GitHub Desktop.
Save SeanChristopherConway/6c4371b0ba2c7f532ac4f6aa5cf4f04d to your computer and use it in GitHub Desktop.
Log Request Body for Debugging (golang)
buf, bodyErr := ioutil.ReadAll(r.Body)
if bodyErr != nil {
log.Print("bodyErr ", bodyErr.Error())
http.Error(w, bodyErr.Error(), http.StatusInternalServerError)
return
}
rdr1 := ioutil.NopCloser(bytes.NewBuffer(buf))
rdr2 := ioutil.NopCloser(bytes.NewBuffer(buf))
log.Printf("BODY: %q", rdr1)
r.Body = rdr2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment