net
CUE v0.18.0
Package net provides net-related type definitions.
The IP-related definitions can be represented as either a string or a list of byte values. To allow one format over an other these types can be further constraint using string or [...]. For instance,
// multicast defines a multicast IP address in string form.
multicast: net.MulticastIP & string // unicast defines a global unicast IP address in list form.
unicast: net.GlobalUnicastIP & [...]Constants
IPv4len
IPv4len: 4IPv6len
IPv6len: 16Schemas
#CIDR
#CIDR: string | bytesA #CIDR is a subnet in CIDR notation, such as "192.0.2.0/24", as a string or its bytes.
#IP
#IP: string | bytes | [...int]An #IP is an IP address in any of the forms the builtins of this package accept: its textual representation as a string or as bytes, such as "192.0.2.1" or "2001:db8::68", or a list of the address's byte values.
Functions
AbsURL validator
validator form
validator(string)call form
func(s: string) -> boolAbsURL validates that s is an absolute URL.
AddIP
AddIP: func(ip: #IP, offset: int) -> stringAddIP adds a numerical offset to a given IP address. The address can be provided as a string, byte array, or CIDR subnet notation. It returns the resulting IP address or CIDR subnet notation as a string.
AddIPCIDR
AddIPCIDR: func(ip: #CIDR, offset: int) -> stringAddIPCIDR adds a numerical offset to a given CIDR subnet string, returning a CIDR string.
CompareIP
CompareIP: func(ip1: #IP, ip2: #IP) -> intCompareIP compares two IP addresses and returns an integer: -1 if ip1 sorts before ip2, 0 if they are equal, and +1 if ip1 sorts after ip2. IPv4 addresses sort before IPv6 addresses.
The addresses may be strings or lists of bytes.
FQDN validator
validator form
validator(string)call form
func(s: string) -> boolFQDN reports whether is a valid fully qualified domain name.
FQDN allows only ASCII characters as prescribed by RFC 1034 (A-Z, a-z, 0-9 and the hyphen).
GlobalUnicastIP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolGlobalUnicastIP reports whether ip is a global unicast address.
The identification of global unicast addresses uses address type identification as defined in RFC 1122, RFC 4632 and RFC 4291 with the exception of IPv4 directed broadcast addresses. It returns true even if ip is in IPv4 private address space or local IPv6 unicast address space.
InCIDR validator
validator form
func(cidr: #CIDR) -> validator(#IP)call form
func(ip: #IP, cidr: #CIDR) -> boolInCIDR reports whether an IP address is contained a CIDR subnet string.
InterfaceLocalMulticastIP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolInterfaceLocalMulticastIP reports whether ip is an interface-local multicast address.
IP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolIP reports whether ip is a valid IPv4 or IPv6 address.
The address may be a string or list of bytes.
IPCIDR validator
validator form
validator(#CIDR)call form
func(ip: #CIDR) -> boolIPCIDR reports whether ip is a valid IPv4 or IPv6 address with CIDR subnet notation.
The address may be a string or list of bytes.
IPString
IPString: func(ip: #IP) -> stringIPString returns the string form of the IP address ip. It returns one of 4 forms:
- "<nil>", if ip has length 0 - dotted decimal ("192.0.2.1"), if ip is an IPv4 or IP4-mapped IPv6 address - IPv6 ("2001:db8::1"), if ip is a valid IPv6 address - the hexadecimal form of ip, without punctuation, if no other cases apply
IPv4 validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolIPv4 reports whether ip is a valid IPv4 address.
The address may be a string or list of bytes.
IPv6 validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolIPv6 reports whether ip is a valid IPv6 address.
The address may be a string or list of bytes.
JoinHostPort
JoinHostPort: func(host: #IP, port: string | bytes | int) -> stringJoinHostPort combines host and port into a network address of the form "host:port". If host contains a colon, as found in literal IPv6 addresses, then JoinHostPort returns "[host]:port".
See func Dial for a description of the host and port parameters.
LinkLocalMulticastIP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolLinkLocalMulticastIP reports whether ip is a link-local multicast address.
LinkLocalUnicastIP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolLinkLocalUnicastIP reports whether ip is a link-local unicast address.
LoopbackIP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolLoopbackIP reports whether ip is a loopback address.
MulticastIP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolMulticastIP reports whether ip is a multicast address.
ParseCIDR
ParseCIDR: func(s: string) -> {...}ParseCIDR parses a CIDR notation string and returns its components: prefix_mask (e.g. "255.255.255.0"), prefix_len (e.g. 24), prefix_addr (e.g. "10.20.30.0"), and broadcast_addr (e.g. "10.20.30.255"). broadcast_addr is only set for IPv4 CIDRs.
ParseIP
ParseIP: func(s: string) -> [...]ParseIP parses s as an IP address, returning the result. The string s can be in dotted decimal ("192.0.2.1") or IPv6 ("2001:db8::68") form. If s is not a valid textual representation of an IP address, ParseIP returns an error.
PathEscape
PathEscape: func(s: string) -> stringPathEscape escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.
PathUnescape
PathUnescape: func(s: string) -> stringPathUnescape does the inverse transformation of PathEscape, converting each 3-byte encoded substring of the form "%AB" into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits.
PathUnescape is identical to QueryUnescape except that it does not unescape '+' to ' ' (space).
QueryEscape
QueryEscape: func(s: string) -> stringQueryEscape escapes the string so it can be safely placed inside a URL query.
QueryUnescape
QueryUnescape: func(s: string) -> stringQueryUnescape does the inverse transformation of QueryEscape, converting each 3-byte encoded substring of the form "%AB" into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits.
SplitHostPort
SplitHostPort: func(s: string) -> [...string]SplitHostPort splits a network address of the form "host:port", "host%zone:port", "[host]:port" or "[host%zone]:port" into host or host%zone and port.
A literal IPv6 address in hostport must be enclosed in square brackets, as in "[::1]:80", "[::1%lo0]:80".
ToIP16
ToIP16: func(ip: #IP) -> [...]ToIP16 converts a given IP address, which may be a string or a list, to its 16-byte representation.
ToIP4
ToIP4: func(ip: #IP) -> [...]ToIP4 converts a given IP address, which may be a string or a list, to its 4-byte representation.
UnspecifiedIP validator
validator form
validator(#IP)call form
func(ip: #IP) -> boolUnspecifiedIP reports whether ip is an unspecified address, either the IPv4 address "0.0.0.0" or the IPv6 address "::".
URL validator
validator form
validator(string)call form
func(s: string) -> boolURL validates that s is a valid relative or absolute URL.