Use go standard lib to support the IPv4 and IPv6 compat.
Use go standard lib to support the IPv4 and IPv6 compatible when joining IP and Port together, rather than cumbersome assertions.
@@ -21,13 +21,9 @@ const DefaultWeight = 1
// string, the IP address should be enclosed in square brackets followed by
// the port.
func PublicAddressToString(addr *l5dNetPb.TcpAddress) string {
- var s string
- if addr.GetIp().GetIpv6() != nil {
- s = "[%s]:%d"
- } else {
- s = "%s:%d"
- }
- return fmt.Sprintf(s, PublicIPToString(addr.GetIp()), addr.GetPort())
+ strIP := PublicIPToString(addr.GetIp())
+ strPort := strconv.Itoa(int(addr.GetPort()))
+ return net.JoinHostPort(strIP, strPort)
}
// PublicIPToString formats a Viz API IPAddress as a string.
