From ebbaee6ed4e1d71ed6671f66fb72f14d08ac5977 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 20 Aug 2022 20:18:03 +0200 Subject: [PATCH 1/2] registryurl: remove fallback code for go < 1.8 Signed-off-by: Sebastiaan van Stijn --- registryurl/parse.go | 10 +++++++++ registryurl/url_go18.go | 17 --------------- registryurl/url_non_go18.go | 41 ------------------------------------- 3 files changed, 10 insertions(+), 58 deletions(-) delete mode 100644 registryurl/url_go18.go delete mode 100644 registryurl/url_non_go18.go diff --git a/registryurl/parse.go b/registryurl/parse.go index 76171328..3fa1e4e4 100644 --- a/registryurl/parse.go +++ b/registryurl/parse.go @@ -35,3 +35,13 @@ func Parse(registryURL string) (*url.URL, error) { u.RawQuery = "" 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() +} diff --git a/registryurl/url_go18.go b/registryurl/url_go18.go deleted file mode 100644 index 2bfc1538..00000000 --- a/registryurl/url_go18.go +++ /dev/null @@ -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() -} diff --git a/registryurl/url_non_go18.go b/registryurl/url_non_go18.go deleted file mode 100644 index 7c8a88fd..00000000 --- a/registryurl/url_non_go18.go +++ /dev/null @@ -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(":"):] -} From 70f476531f36cde0be4b3351c53a56239e09467c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 20 Aug 2022 20:25:03 +0200 Subject: [PATCH 2/2] registryurl: deprecate GetHostname(), GetPort() These were just wrappers for url.Hostname() and url.Port() Signed-off-by: Sebastiaan van Stijn --- osxkeychain/osxkeychain_darwin.go | 6 +++--- registryurl/parse.go | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/osxkeychain/osxkeychain_darwin.go b/osxkeychain/osxkeychain_darwin.go index a6d37303..dffec45e 100644 --- a/osxkeychain/osxkeychain_darwin.go +++ b/osxkeychain/osxkeychain_darwin.go @@ -138,7 +138,7 @@ func (h Osxkeychain) List() (map[string]string, error) { listLen = int(listLenC) pathTmp := (*[1 << 30]*C.char)(unsafe.Pointer(pathsC))[:listLen:listLen] acctTmp := (*[1 << 30]*C.char)(unsafe.Pointer(acctsC))[:listLen:listLen] - //taking the array of c strings into go while ignoring all the stuff irrelevant to credentials-helper + // taking the array of c strings into go while ignoring all the stuff irrelevant to credentials-helper resp := make(map[string]string) for i := 0; i < listLen; i++ { if C.GoString(pathTmp[i]) == "0" { @@ -160,7 +160,7 @@ func splitServer(serverURL string) (*C.struct_Server, error) { proto = C.kSecProtocolTypeHTTP } var port int - p := registryurl.GetPort(u) + p := u.Port() if p != "" { port, err = strconv.Atoi(p) if err != nil { @@ -170,7 +170,7 @@ func splitServer(serverURL string) (*C.struct_Server, error) { return &C.struct_Server{ proto: C.SecProtocolType(proto), - host: C.CString(registryurl.GetHostname(u)), + host: C.CString(u.Hostname()), port: C.uint(port), path: C.CString(u.Path), }, nil diff --git a/registryurl/parse.go b/registryurl/parse.go index 3fa1e4e4..f9a9f888 100644 --- a/registryurl/parse.go +++ b/registryurl/parse.go @@ -28,7 +28,7 @@ func Parse(registryURL string) (*url.URL, error) { return nil, errors.New("unsupported scheme: " + u.Scheme) } - if GetHostname(u) == "" { + if u.Hostname() == "" { return nil, errors.New("no hostname in URL") } @@ -37,11 +37,15 @@ func Parse(registryURL string) (*url.URL, error) { } // 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() }