8 // Extracts the port as an integer from an address string.
9 func addrPortOrZero(addr net.Addr) int {
10 switch raw := addr.(type) {
16 _, port, err := net.SplitHostPort(addr.String())
20 i64, err := strconv.ParseInt(port, 0, 0)
28 func addrIpOrNil(addr net.Addr) net.IP {
32 switch raw := addr.(type) {
38 host, _, err := net.SplitHostPort(addr.String())
42 return net.ParseIP(host)
46 type ipPortAddr struct {
51 func (ipPortAddr) Network() string {
55 func (me ipPortAddr) String() string {
56 return net.JoinHostPort(me.IP.String(), strconv.FormatInt(int64(me.Port), 10))
59 func tryIpPortFromNetAddr(na net.Addr) (ret ipPortAddr, ok bool) {
60 ret.IP = addrIpOrNil(na)
64 ret.Port = addrPortOrZero(na)