To make an HTTP trace request in Go, you can use the net/http package along with the httptrace package to trace various events in the request's lifecycle. Here's an example code snippet:
main.go683 chars37 linesIn this code, we first create a new http.Request using the http.NewRequest function. We then create a new context using httptrace.WithClientTrace, which initializes a ClientTrace with a few callback functions that will be called during the request.
In this example, we've added a GotConn callback function to trace when a connection is established. When the request is executed using the client.Do(req) call, the GotConn function will be called with information about the connection that was established.
Finally, we print the response from the server. Note that you can add more callback functions to the ClientTrace struct to trace more events such as DNS lookups and TLS handshakes.
gistlibby LogSnag