isValidTarget checks if a string is a valid target, i.e., a public domain name or an IP address.
(s string)
| 408 | // isValidTarget checks if a string is a valid target, i.e., a public |
| 409 | // domain name or an IP address. |
| 410 | func isValidTarget(s string) bool { |
| 411 | if s == "" { |
| 412 | return false |
| 413 | } |
| 414 | if ip := net.ParseIP(s); ip != nil { |
| 415 | return true |
| 416 | } |
| 417 | // Assume domain name and require at least one level above TLD |
| 418 | i := strings.LastIndex(s, ".") |
| 419 | if i == -1 || len(s)-1 == i { |
| 420 | return false |
| 421 | } |
| 422 | // TLD may not start with a number |
| 423 | if c := s[i+1]; c >= '0' && c <= '9' { |
| 424 | return false |
| 425 | } |
| 426 | return true |
| 427 | } |
| 428 | |
| 429 | // isValidLimit retruns a value indicating whether the limit is valid, |
| 430 | // e.g., for requests without an API key the limit is capped at 20. |
no outgoing calls