July 26, 2023
RoundTrip Logging Within Go’s http.Client
Ok, so let’s say you have an HTTP client where you need to get information from the request and response calls for logging or debugging reasons. One way to do this is to create a custom RoundTripper to handle said logging.
What is a RoundTripper?
A RoundTripper is an interface that implements the RoundTrip function which makes the HTTP request and response on behalf of the http.Client, within the client’s Do() function. There is a field on the client called Transport that holds the implementation. Go will use the default version if no custom RoundTripper is provided.