mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
registryurl: remove fallback code for go < 1.8
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -35,3 +35,13 @@ func Parse(registryURL string) (*url.URL, error) {
|
|||||||
u.RawQuery = ""
|
u.RawQuery = ""
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHostname returns the hostname of the URL
|
||||||
|
func GetHostname(u *url.URL) string {
|
||||||
|
return u.Hostname()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPort returns the port number of the URL
|
||||||
|
func GetPort(u *url.URL) string {
|
||||||
|
return u.Port()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
//+build go1.8
|
|
||||||
|
|
||||||
package registryurl
|
|
||||||
|
|
||||||
import (
|
|
||||||
url "net/url"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetHostname returns the hostname of the URL
|
|
||||||
func GetHostname(u *url.URL) string {
|
|
||||||
return u.Hostname()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPort returns the port number of the URL
|
|
||||||
func GetPort(u *url.URL) string {
|
|
||||||
return u.Port()
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
//+build !go1.8
|
|
||||||
|
|
||||||
package registryurl
|
|
||||||
|
|
||||||
import (
|
|
||||||
url "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(":"):]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user