Forked from briangershon/gist:fa9feb08e6a65d52bdc35c738d8cf104
Created
March 2, 2021 06:01
-
-
Save ashutosh-mishra/e23ed0a73dd522abbad04ccf654ddb84 to your computer and use it in GitHub Desktop.
Log Request Body for Debugging (golang)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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