Move golang code to third_party

This commit is contained in:
Andy Goldstein
2015-02-20 20:00:31 -05:00
parent 86a0193f51
commit 44d41a0f1b
6 changed files with 80 additions and 25 deletions

View File

@@ -19,7 +19,6 @@ package util
import (
"fmt"
"net"
"net/url"
"strings"
)
@@ -62,24 +61,3 @@ func (ipnet *IPNet) Set(value string) error {
func (*IPNet) Type() string {
return "ipNet"
}
// 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
}