]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - tls/hostport.go
Compatibility with raw IPv6 addresses as hostname
[tofuproxy.git] / tls / hostport.go
diff --git a/tls/hostport.go b/tls/hostport.go
new file mode 100644 (file)
index 0000000..14b1ce3
--- /dev/null
@@ -0,0 +1,20 @@
+package tofuproxy
+
+import (
+       "net"
+       "strings"
+)
+
+func SplitHostPort(addr string) (string, string, error) {
+       if net.ParseIP(addr) != nil {
+               return addr, "", nil
+       }
+       host, port, err := net.SplitHostPort(addr)
+       if err == nil {
+               return host, port, nil
+       }
+       if strings.Contains(err.Error(), "missing port") {
+               return addr, "", nil
+       }
+       return addr, "", err
+}