handle ipv6 addresses

This commit is contained in:
Chris Lu
2021-09-07 16:43:54 -07:00
parent 35c8ea495f
commit 0128239c0f
16 changed files with 42 additions and 20 deletions

View File

@@ -2,6 +2,8 @@ package util
import (
"net"
"strconv"
"strings"
"github.com/chrislusf/seaweedfs/weed/glog"
)
@@ -33,3 +35,11 @@ func DetectedHostAddress() string {
return "localhost"
}
func JoinHostPort(host string, port int) string {
portStr := strconv.Itoa(port)
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
return host + ":" + portStr
}
return net.JoinHostPort(host, portStr)
}