mirror of
https://github.com/kubernetes/client-go.git
synced 2025-10-22 14:32:43 +00:00
(https://github.com/kubernetes/contrib/tree/master/mungegithub) copied from https://github.com/kubernetes/kubernetes.git, branch master, last commit is 71ba8a90f0a4f3a307cffeb8f8566d13277cb135
28 lines
702 B
Go
28 lines
702 B
Go
package netutil
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// FROM: http://golang.org/src/net/http/client.go
|
|
// Given a string of the form "host", "host:port", or "[ipv6::address]:port",
|
|
// return true if the string includes a port.
|
|
func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
|
|
|
|
// FROM: http://golang.org/src/net/http/transport.go
|
|
var portMap = map[string]string{
|
|
"http": "80",
|
|
"https": "443",
|
|
}
|
|
|
|
// FROM: http://golang.org/src/net/http/transport.go
|
|
// canonicalAddr returns url.Host but always with a ":port" suffix
|
|
func CanonicalAddr(url *url.URL) string {
|
|
addr := url.Host
|
|
if !hasPort(addr) {
|
|
return addr + ":" + portMap[url.Scheme]
|
|
}
|
|
return addr
|
|
}
|