diff options
| author | Kevin Burke <kev@inburke.com> | 2017-05-07 23:19:31 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-05-19 19:01:49 +0000 |
| commit | b3b9b5e463cefb5eaad69628709ed5a0c1cb658f (patch) | |
| tree | c83a05d8ec11176a1b560d77076149b16c3cf34e /src | |
| parent | 495f55d27d16b2b8deee4b7e79186b07336f6765 (diff) | |
| download | go-b3b9b5e463cefb5eaad69628709ed5a0c1cb658f.tar.xz | |
net/url: add examples for URL.Hostname and URL.RequestURI
Change-Id: I72a10cd5dfb863f8219bb3b5b8280c017f523cf4
Reviewed-on: https://go-review.googlesource.com/42856
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/url/example_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/net/url/example_test.go b/src/net/url/example_test.go index 0b8b84af36..d352c55b6f 100644 --- a/src/net/url/example_test.go +++ b/src/net/url/example_test.go @@ -81,6 +81,31 @@ func ExampleParseQuery() { // {"x":["1"], "y":["2", "3"], "z":[""]} } +func ExampleURL_Hostname() { + u, err := url.Parse("https://example.org:8000/path") + if err != nil { + log.Fatal(err) + } + fmt.Println(u.Hostname()) + u, err = url.Parse("https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:17000") + if err != nil { + log.Fatal(err) + } + fmt.Println(u.Hostname()) + // Output: + // example.org + // 2001:0db8:85a3:0000:0000:8a2e:0370:7334 +} + +func ExampleURL_RequestURI() { + u, err := url.Parse("https://example.org/path?foo=bar") + if err != nil { + log.Fatal(err) + } + fmt.Println(u.RequestURI()) + // Output: /path?foo=bar +} + func toJSON(m interface{}) string { js, err := json.Marshal(m) if err != nil { |
