isLoopback identifies if a uri's host is on a loopback address
(uri string)
| 447 | |
| 448 | // isLoopback identifies if a uri's host is on a loopback address |
| 449 | func isLoopback(uri string) (bool, error) { |
| 450 | u, err := url.Parse(uri) |
| 451 | if err != nil { |
| 452 | return false, err |
| 453 | } |
| 454 | |
| 455 | host := u.Hostname() |
| 456 | if len(host) == 0 { |
| 457 | return false, fmt.Errorf("can't parse host from uri: %s", uri) |
| 458 | } |
| 459 | |
| 460 | ips, err := net.LookupHost(host) |
| 461 | if err != nil { |
| 462 | return false, err |
| 463 | } |
| 464 | for _, ip := range ips { |
| 465 | if !net.ParseIP(ip).IsLoopback() { |
| 466 | return false, nil |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | return true, nil |
| 471 | } |
no outgoing calls
no test coverage detected