Created
February 5, 2023 15:03
-
-
Save mstrYoda/28ab29818e9955d0bcadb3c16b65bbbb to your computer and use it in GitHub Desktop.
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
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