http urls monitor.

net.go 494B

12345678910111213141516171819202122232425
  1. package swag
  2. import (
  3. "net"
  4. "strconv"
  5. )
  6. // SplitHostPort splits a network address into a host and a port.
  7. // The port is -1 when there is no port to be found
  8. func SplitHostPort(addr string) (host string, port int, err error) {
  9. h, p, err := net.SplitHostPort(addr)
  10. if err != nil {
  11. return "", -1, err
  12. }
  13. if p == "" {
  14. return "", -1, &net.AddrError{Err: "missing port in address", Addr: addr}
  15. }
  16. pi, err := strconv.Atoi(p)
  17. if err != nil {
  18. return "", -1, err
  19. }
  20. return h, pi, nil
  21. }