Commit b3b9b5e4 authored by Kevin Burke's avatar Kevin Burke Committed by Brad Fitzpatrick

net/url: add examples for URL.Hostname and URL.RequestURI

Change-Id: I72a10cd5dfb863f8219bb3b5b8280c017f523cf4
Reviewed-on: https://go-review.googlesource.com/42856Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent 495f55d2
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment