url_1_7.go 627 B

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