mirror of
https://github.com/genuinetools/reg.git
synced 2024-08-18 04:50:23 -04:00
42 lines
745 B
Go
42 lines
745 B
Go
//+build !go1.8
|
|
|
|
package osxkeychain
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
func getHostname(u *url.URL) string {
|
|
return stripPort(u.Host)
|
|
}
|
|
|
|
func getPort(u *url.URL) string {
|
|
return portOnly(u.Host)
|
|
}
|
|
|
|
func stripPort(hostport string) string {
|
|
colon := strings.IndexByte(hostport, ':')
|
|
if colon == -1 {
|
|
return hostport
|
|
}
|
|
if i := strings.IndexByte(hostport, ']'); i != -1 {
|
|
return strings.TrimPrefix(hostport[:i], "[")
|
|
}
|
|
return hostport[:colon]
|
|
}
|
|
|
|
func portOnly(hostport string) string {
|
|
colon := strings.IndexByte(hostport, ':')
|
|
if colon == -1 {
|
|
return ""
|
|
}
|
|
if i := strings.Index(hostport, "]:"); i != -1 {
|
|
return hostport[i+len("]:"):]
|
|
}
|
|
if strings.Contains(hostport, "]") {
|
|
return ""
|
|
}
|
|
return hostport[colon+len(":"):]
|
|
}
|