1// +build !go1.8
2
3package aws
4
5import (
6	"net/url"
7	"strings"
8)
9
10// URLHostname will extract the Hostname without port from the URL value.
11//
12// Copy of Go 1.8's net/url#URL.Hostname functionality.
13func URLHostname(url *url.URL) string {
14	return stripPort(url.Host)
15
16}
17
18// stripPort is copy of Go 1.8 url#URL.Hostname functionality.
19// https://golang.org/src/net/url/url.go
20func stripPort(hostport string) string {
21	colon := strings.IndexByte(hostport, ':')
22	if colon == -1 {
23		return hostport
24	}
25	if i := strings.IndexByte(hostport, ']'); i != -1 {
26		return strings.TrimPrefix(hostport[:i], "[")
27	}
28	return hostport[:colon]
29}
30