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