pkg/net¶
Helpers for validating network address strings. The package currently exposes strict IPv4 and IPv6 checkers for input validation in config, API payloads, and CLI flags.
Quick Start¶
API Cheatsheet¶
| Function | Purpose |
|---|---|
IsValidIP(value string) bool |
returns true only for syntactically valid IPv4 or IPv6 addresses |
IsValidIPv4(value string) bool |
returns true only for syntactically valid IPv4 addresses |
IsValidIPv6(value string) bool |
returns true only for syntactically valid IPv6 addresses |
IsValidURL(value string) bool |
returns true only for syntactically valid URLs with scheme and host |
Examples¶
Accept any valid IP (v4 or v6)¶
Accept valid IPv4¶
Reject invalid input¶
Accept valid IPv6¶
Reject invalid IPv6 input¶
Accept valid URLs¶
Reject invalid URLs¶
Behavior Notes¶
IP Validation Specifics¶
- Validation is syntactic only; it does not check host reachability.
- Reserved/private/public ranges are all treated as valid if the address format is correct.
- The helper does not trim input. Normalize user input before validation if needed.
URL Validation Specifics¶
IsValidURLrequires both a scheme (http, https, ftp, etc.) and a host to be present.- This is stricter than
net.ParseURL, rejecting permissive edge cases like scheme-only or host-only strings. - Supports any valid scheme (http, https, ftp, ws, custom protocols, etc.).
- Accepts URLs with ports, paths, query strings, fragments, and user info.
- Does not validate the scheme against a whitelist; any non-empty valid scheme is accepted (use additional logic if you need to restrict schemes).