From 4187e1f49f45b1cfa66e7cdf8c118ee926285019 Mon Sep 17 00:00:00 2001 From: Billy Lynch Date: Fri, 19 Aug 2016 01:40:08 -0400 Subject: [PATCH] net/http/httptrace: add simple example and fix copyright header Partially addresses #16360 Change-Id: I67a328302d7d91231f348d934e4232fcb844830a Reviewed-on: https://go-review.googlesource.com/27398 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/httptrace/example_test.go | 25 +++++++++++++++++++++++++ src/net/http/httptrace/trace.go | 2 +- src/net/http/httptrace/trace_test.go | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/net/http/httptrace/example_test.go diff --git a/src/net/http/httptrace/example_test.go b/src/net/http/httptrace/example_test.go new file mode 100644 index 00000000000..c8ed4464359 --- /dev/null +++ b/src/net/http/httptrace/example_test.go @@ -0,0 +1,25 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package httptrace_test + +import ( + "fmt" + "net/http" + "net/http/httptrace" +) + +func ExampleTrace() { + req, _ := http.NewRequest("GET", "http://example.com", nil) + trace := &httptrace.ClientTrace{ + GotConn: func(connInfo httptrace.GotConnInfo) { + fmt.Printf("Got Conn: %+v\n", connInfo) + }, + DNSDone: func(dnsInfo httptrace.DNSDoneInfo) { + fmt.Printf("DNS Info: %+v\n", dnsInfo) + }, + } + req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) + http.DefaultClient.Do(req) +} diff --git a/src/net/http/httptrace/trace.go b/src/net/http/httptrace/trace.go index 6f187a7b694..93c07b8ac3a 100644 --- a/src/net/http/httptrace/trace.go +++ b/src/net/http/httptrace/trace.go @@ -1,6 +1,6 @@ // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file.h +// license that can be found in the LICENSE file. // Package httptrace provides mechanisms to trace the events within // HTTP client requests. diff --git a/src/net/http/httptrace/trace_test.go b/src/net/http/httptrace/trace_test.go index 77941b35198..bb57ada8531 100644 --- a/src/net/http/httptrace/trace_test.go +++ b/src/net/http/httptrace/trace_test.go @@ -1,6 +1,6 @@ // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file.h +// license that can be found in the LICENSE file. package httptrace