(network string, address string, replace bool)
| 93 | } |
| 94 | |
| 95 | func 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 | } |
no test coverage detected