You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
307 B

  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. }