1//+build !go1.8 2 3package osxkeychain 4 5import ( 6 "net/url" 7 "strings" 8) 9 10func getHostname(u *url.URL) string { 11 return stripPort(u.Host) 12} 13 14func getPort(u *url.URL) string { 15 return portOnly(u.Host) 16} 17 18func stripPort(hostport string) string { 19 colon := strings.IndexByte(hostport, ':') 20 if colon == -1 { 21 return hostport 22 } 23 if i := strings.IndexByte(hostport, ']'); i != -1 { 24 return strings.TrimPrefix(hostport[:i], "[") 25 } 26 return hostport[:colon] 27} 28 29func portOnly(hostport string) string { 30 colon := strings.IndexByte(hostport, ':') 31 if colon == -1 { 32 return "" 33 } 34 if i := strings.Index(hostport, "]:"); i != -1 { 35 return hostport[i+len("]:"):] 36 } 37 if strings.Contains(hostport, "]") { 38 return "" 39 } 40 return hostport[colon+len(":"):] 41} 42