Skip to content

Instantly share code, notes, and snippets.

@mstrYoda
Created February 5, 2023 15:03
Show Gist options
  • Save mstrYoda/28ab29818e9955d0bcadb3c16b65bbbb to your computer and use it in GitHub Desktop.
Save mstrYoda/28ab29818e9955d0bcadb3c16b65bbbb to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptrace"
"time"
)
func main() {
request, _ := http.NewRequest("GET", "http://localhost:8080", nil)
ctx := context.Background()
trace := &httptrace.ClientTrace{
PutIdleConn: func(err error) {
fmt.Println("put idle conn")
},
ConnectStart: func(network, addr string) {
fmt.Println("connect start")
},
GetConn: func(hostPort string) {
fmt.Println("get conn")
},
}
req := request.WithContext(httptrace.WithClientTrace(ctx, trace))
for {
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
io.ReadAll(resp.Body)
time.Sleep(1 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment