Skip to content

Instantly share code, notes, and snippets.

@flexzuu
Created August 13, 2019 15:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flexzuu/95cfc042d27a152c64ccdca0a36c75d8 to your computer and use it in GitHub Desktop.
Save flexzuu/95cfc042d27a152c64ccdca0a36c75d8 to your computer and use it in GitHub Desktop.
wrap a transport to log the body
import "github.com/motemen/go-loghttp"
httpClient.Transport = &loghttp.Transport{
Transport: httpClient.Transport,
LogRequest: func(req *http.Request) {
b, _ := httputil.DumpRequestOut(req, true)
log.Printf("out body: %s", string(b))
},
LogResponse: func(resp *http.Response) {
b, _ := httputil.DumpResponse(resp, true)
log.Printf("in body: %s", string(b))
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment