Created
August 13, 2019 15:46
-
-
Save flexzuu/95cfc042d27a152c64ccdca0a36c75d8 to your computer and use it in GitHub Desktop.
wrap a transport to log the body
This file contains 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
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