github.com/ck00004/CobaltStrikeParser-Go@v1.0.14/lib/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 "log" 10 11 "github.com/ck00004/CobaltStrikeParser-Go/lib/http/httptrace" 12 13 "github.com/ck00004/CobaltStrikeParser-Go/lib/http" 14 ) 15 16 func Example() { 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 }