MCPcopy
hub / github.com/CodisLabs/codis / replaceUnspecifiedIP

Function replaceUnspecifiedIP

pkg/utils/resolver.go:95–121  ·  view source on GitHub ↗
(network string, address string, replace bool)

Source from the content-addressed store, hash-verified

93}
94
95func replaceUnspecifiedIP(network string, address string, replace bool) (string, error) {
96 switch network {
97 default:
98 return "", errors.Trace(net.UnknownNetworkError(network))
99 case "unix", "unixpacket":
100 return address, nil
101 case "tcp", "tcp4", "tcp6":
102 tcpAddr, err := net.ResolveTCPAddr(network, address)
103 if err != nil {
104 return "", errors.Trace(err)
105 }
106 if tcpAddr.Port != 0 {
107 if !tcpAddr.IP.IsUnspecified() {
108 return address, nil
109 }
110 if replace {
111 if len(HostIPs) != 0 {
112 return net.JoinHostPort(Hostname, strconv.Itoa(tcpAddr.Port)), nil
113 }
114 if len(InterfaceIPs) != 0 {
115 return net.JoinHostPort(InterfaceIPs[0], strconv.Itoa(tcpAddr.Port)), nil
116 }
117 }
118 }
119 return "", errors.Errorf("resolve address '%s' to '%s'", address, tcpAddr.String())
120 }
121}

Callers 1

ReplaceUnspecifiedIPFunction · 0.85

Calls 2

ErrorfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected