mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-14 08:21:28 +05:30
Merge pull request #225 from thaJeztah/drop_go1.8
registryurl: remove fallback code for go < 1.8
This commit is contained in:
@@ -160,7 +160,7 @@ func splitServer(serverURL string) (*C.struct_Server, error) {
|
|||||||
proto = C.kSecProtocolTypeHTTP
|
proto = C.kSecProtocolTypeHTTP
|
||||||
}
|
}
|
||||||
var port int
|
var port int
|
||||||
p := registryurl.GetPort(u)
|
p := u.Port()
|
||||||
if p != "" {
|
if p != "" {
|
||||||
port, err = strconv.Atoi(p)
|
port, err = strconv.Atoi(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -170,7 +170,7 @@ func splitServer(serverURL string) (*C.struct_Server, error) {
|
|||||||
|
|
||||||
return &C.struct_Server{
|
return &C.struct_Server{
|
||||||
proto: C.SecProtocolType(proto),
|
proto: C.SecProtocolType(proto),
|
||||||
host: C.CString(registryurl.GetHostname(u)),
|
host: C.CString(u.Hostname()),
|
||||||
port: C.uint(port),
|
port: C.uint(port),
|
||||||
path: C.CString(u.Path),
|
path: C.CString(u.Path),
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
+15
-1
@@ -28,10 +28,24 @@ func Parse(registryURL string) (*url.URL, error) {
|
|||||||
return nil, errors.New("unsupported scheme: " + u.Scheme)
|
return nil, errors.New("unsupported scheme: " + u.Scheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
if GetHostname(u) == "" {
|
if u.Hostname() == "" {
|
||||||
return nil, errors.New("no hostname in URL")
|
return nil, errors.New("no hostname in URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
u.RawQuery = ""
|
u.RawQuery = ""
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHostname returns the hostname of the URL
|
||||||
|
//
|
||||||
|
// Deprecated: use url.Hostname()
|
||||||
|
func GetHostname(u *url.URL) string {
|
||||||
|
return u.Hostname()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPort returns the port number of the URL
|
||||||
|
//
|
||||||
|
// Deprecated: use url.Port()
|
||||||
|
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