Documentation ¶
Overview ¶
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 & [...]
Package net defines net-related types.
Index ¶
- Constants
- func FQDN(s string) bool
- func GlobalUnicastIP(ip cue.Value) bool
- func IP(ip cue.Value) bool
- func IPCIDR(ip cue.Value) (bool, error)
- func IPString(ip cue.Value) (string, error)
- func IPv4(ip cue.Value) bool
- func IPv6(ip cue.Value) bool
- func InterfaceLocalMulticastIP(ip cue.Value) bool
- func JoinHostPort(host, port cue.Value) (string, error)
- func LinkLocalMulticastIP(ip cue.Value) bool
- func LinkLocalUnicastIP(ip cue.Value) bool
- func LoopbackIP(ip cue.Value) bool
- func MulticastIP(ip cue.Value) bool
- func ParseIP(s string) ([]uint, error)
- func PathEscape(s string) string
- func PathUnescape(s string) (string, error)
- func QueryEscape(s string) string
- func QueryUnescape(s string) (string, error)
- func SplitHostPort(s string) (hostport []string, err error)
- func ToIP16(ip cue.Value) ([]uint, error)
- func ToIP4(ip cue.Value) ([]uint, error)
- func UnspecifiedIP(ip cue.Value) bool
Constants ¶
const ( IPv4len = 4 IPv6len = 16 )
IP address lengths (bytes).
Variables ¶
This section is empty.
Functions ¶
func FQDN ¶
FQDN 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).
func GlobalUnicastIP ¶
GlobalUnicastIP 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.
func IP ¶
IP reports whether ip is a valid IPv4 or IPv6 address.
The address may be a string or list of bytes.
func IPCIDR ¶ added in v0.4.3
IPCIDR reports whether ip is a valid IPv4 or IPv6 address with CIDR subnet notation.
The address may be a string or list of bytes.
func IPString ¶
IPString 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
func IPv4 ¶
IPv4 reports whether ip is a valid IPv4 address.
The address may be a string or list of bytes.
func IPv6 ¶ added in v0.8.0
IPv6 reports whether ip is a valid IPv6 address.
The address may be a string or list of bytes.
func InterfaceLocalMulticastIP ¶
InterfaceLocalMulticastIP reports whether ip is an interface-local multicast address.
func JoinHostPort ¶
JoinHostPort 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.
func LinkLocalMulticastIP ¶
LinkLocalMulticast reports whether ip is a link-local multicast address.
func LinkLocalUnicastIP ¶
LinkLocalUnicastIP reports whether ip is a link-local unicast address.
func LoopbackIP ¶
LoopbackIP reports whether ip is a loopback address.
func MulticastIP ¶
MulticastIP reports whether ip is a multicast address.
func ParseIP ¶
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 nil.
func PathEscape ¶ added in v0.6.0
PathEscape escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.
func PathUnescape ¶ added in v0.6.0
PathUnescape 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).
func QueryEscape ¶ added in v0.6.0
QueryEscape escapes the string so it can be safely placed inside a URL query.
func QueryUnescape ¶ added in v0.6.0
QueryUnescape 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.
func SplitHostPort ¶
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".
func ToIP16 ¶
ToIP16 converts a given IP address, which may be a string or a list, to its 16-byte representation.
func ToIP4 ¶
ToIP4 converts a given IP address, which may be a string or a list, to its 4-byte representation.
func UnspecifiedIP ¶
UnspecifiedIP reports whether ip is an unspecified address, either the IPv4 address "0.0.0.0" or the IPv6 address "::".
Types ¶
This section is empty.