replaceZeroPort substitutes originPort for a node port of "0", which is what CLUSTER SLOTS reports for TLS-only clusters started with `--port 0 --tls-port <port>`. Non-zero ports and addresses without a recoverable origin port are returned unchanged.
(nodeAddr, originPort string)
| 893 | // `--port 0 --tls-port <port>`. Non-zero ports and addresses without a |
| 894 | // recoverable origin port are returned unchanged. |
| 895 | func replaceZeroPort(nodeAddr, originPort string) string { |
| 896 | if originPort == "" || originPort == "0" { |
| 897 | return nodeAddr |
| 898 | } |
| 899 | nodeHost, nodePort, err := net.SplitHostPort(nodeAddr) |
| 900 | if err != nil || nodePort != "0" { |
| 901 | return nodeAddr |
| 902 | } |
| 903 | return net.JoinHostPort(nodeHost, originPort) |
| 904 | } |
| 905 | |
| 906 | // isLoopback returns true if the host is a loopback address. |
| 907 | // For IP addresses, it uses net.IP.IsLoopback(). |