hostport.go 309 B

12345678910111213141516171819
  1. package missinggo
  2. import (
  3. "net"
  4. "strconv"
  5. )
  6. func ParseHostPort(hostport string) (host string, port int, err error) {
  7. host, portStr, err := net.SplitHostPort(hostport)
  8. if err != nil {
  9. return
  10. }
  11. port64, err := strconv.ParseInt(portStr, 0, 0)
  12. if err != nil {
  13. return
  14. }
  15. port = int(port64)
  16. return
  17. }