From ea7797e10aff74258c4c9f29e6cd5b4bd2744d43 Mon Sep 17 00:00:00 2001 From: Phil Kates Date: Thu, 12 Feb 2015 13:19:06 -0800 Subject: [PATCH] url-parsing: Use net.SplitHostPort Use [net.SplitHostPort](https://godoc.org/net#SplitHostPort) instead of strings.Split. This is the more correct way to split the host and port as well as working with IPv6. --- examples/url-parsing/url-parsing.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/url-parsing/url-parsing.go b/examples/url-parsing/url-parsing.go index 991c6e9..a4b300e 100644 --- a/examples/url-parsing/url-parsing.go +++ b/examples/url-parsing/url-parsing.go @@ -4,8 +4,8 @@ package main import "fmt" +import "net" import "net/url" -import "strings" func main() { @@ -35,9 +35,9 @@ func main() { // if present. `Split` the `Host` manually to extract // the port. fmt.Println(u.Host) - h := strings.Split(u.Host, ":") - fmt.Println(h[0]) - fmt.Println(h[1]) + host, port, _ := net.SplitHostPort(u.Host) + fmt.Println(host) + fmt.Println(port) // Here we extract the `path` and the fragment after // the `#`.