aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient/net2/port.go
blob: f83adba2835fca46be1101f9da9e958318cabc12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package net2

import (
	"net"
	"strconv"
)

// Returns the port information.
func GetPort(addr net.Addr) (int, error) {
	_, lport, err := net.SplitHostPort(addr.String())
	if err != nil {
		return -1, err
	}
	lportInt, err := strconv.Atoi(lport)
	if err != nil {
		return -1, err
	}
	return lportInt, nil
}