github.com/ooni/oohttp@v0.7.2/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 "github.com/ooni/oohttp"
    12  	httptrace "github.com/ooni/oohttp/httptrace"
    13  )
    14  
    15  func Example() {
    16  	req, _ := http.NewRequest("GET", "http://example.com", nil)
    17  	trace := &httptrace.ClientTrace{
    18  		GotConn: func(connInfo httptrace.GotConnInfo) {
    19  			fmt.Printf("Got Conn: %+v\n", connInfo)
    20  		},
    21  		DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
    22  			fmt.Printf("DNS Info: %+v\n", dnsInfo)
    23  		},
    24  	}
    25  	req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
    26  	_, err := http.DefaultTransport.RoundTrip(req)
    27  	if err != nil {
    28  		log.Fatal(err)
    29  	}
    30  }