Merge pull request #95 from philk/split_host_port
url-parsing: Use net.SplitHostPort
This commit is contained in:
commit
497e99d58b
@ -4,8 +4,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "net"
|
||||||
import "net/url"
|
import "net/url"
|
||||||
import "strings"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ func main() {
|
|||||||
// if present. `Split` the `Host` manually to extract
|
// if present. `Split` the `Host` manually to extract
|
||||||
// the port.
|
// the port.
|
||||||
fmt.Println(u.Host)
|
fmt.Println(u.Host)
|
||||||
h := strings.Split(u.Host, ":")
|
host, port, _ := net.SplitHostPort(u.Host)
|
||||||
fmt.Println(h[0])
|
fmt.Println(host)
|
||||||
fmt.Println(h[1])
|
fmt.Println(port)
|
||||||
|
|
||||||
// Here we extract the `path` and the fragment after
|
// Here we extract the `path` and the fragment after
|
||||||
// the `#`.
|
// the `#`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user