gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/gmhttp/httptrace/example_test.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package httptrace_test 6 7 import ( 8 "fmt" 9 "log" 10 11 http "gitee.com/ks-custle/core-gm/gmhttp" 12 "gitee.com/ks-custle/core-gm/gmhttp/httptrace" 13 ) 14 15 func Example() { 16 //goland:noinspection HttpUrlsUsage 17 req, _ := http.NewRequest("GET", "http://example.com", nil) 18 trace := &httptrace.ClientTrace{ 19 GotConn: func(connInfo httptrace.GotConnInfo) { 20 fmt.Printf("Got Conn: %+v\n", connInfo) 21 }, 22 DNSDone: func(dnsInfo httptrace.DNSDoneInfo) { 23 fmt.Printf("DNS Info: %+v\n", dnsInfo) 24 }, 25 } 26 req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) 27 _, err := http.DefaultTransport.RoundTrip(req) 28 if err != nil { 29 log.Fatal(err) 30 } 31 }