port.go 307 B

12345678910111213141516171819
  1. package net2
  2. import (
  3. "net"
  4. "strconv"
  5. )
  6. // Returns the port information.
  7. func GetPort(addr net.Addr) (int, error) {
  8. _, lport, err := net.SplitHostPort(addr.String())
  9. if err != nil {
  10. return -1, err
  11. }
  12. lportInt, err := strconv.Atoi(lport)
  13. if err != nil {
  14. return -1, err
  15. }
  16. return lportInt, nil
  17. }