github.com/euank/go@v0.0.0-20160829210321-495514729181/src/net/http/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 "net/http" 10 "net/http/httptrace" 11 ) 12 13 func Example() { 14 req, _ := http.NewRequest("GET", "http://example.com", nil) 15 trace := &httptrace.ClientTrace{ 16 GotConn: func(connInfo httptrace.GotConnInfo) { 17 fmt.Printf("Got Conn: %+v\n", connInfo) 18 }, 19 DNSDone: func(dnsInfo httptrace.DNSDoneInfo) { 20 fmt.Printf("DNS Info: %+v\n", dnsInfo) 21 }, 22 } 23 req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) 24 http.DefaultClient.Do(req) 25 }