Documentation
¶
Overview ¶
Package dnsname contains string functions for working with DNS names.
Index ¶
- func FirstLabel(hostname string) string
- func HasSuffix(name, suffix string) bool
- func NumLabels(hostname string) int
- func SanitizeHostname(hostname string) string
- func SanitizeLabel(label string) string
- func TrimCommonSuffixes(hostname string) string
- func TrimSuffix(name, suffix string) string
- func ValidHostname(hostname string) error
- func ValidLabel(label string) error
- func ValidLabelLike(label string, maxLen int) error
- type FQDN
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstLabel ¶ added in v1.8.0
FirstLabel returns the first DNS label of hostname.
func HasSuffix ¶
HasSuffix reports whether the provided name ends with the component(s) in suffix, ignoring any trailing or leading dots.
If suffix is the empty string, HasSuffix always reports false.
func NumLabels ¶ added in v1.8.0
NumLabels returns the number of DNS labels in hostname. If hostname is empty or the top-level name ".", returns 0.
func SanitizeHostname ¶ added in v1.6.0
SanitizeHostname turns hostname into a valid name label according to RFC 1035.
func SanitizeLabel ¶ added in v1.6.0
SanitizeLabel takes a string intended to be a DNS name label and turns it into a valid name label according to RFC 1035.
func TrimCommonSuffixes ¶ added in v1.6.0
TrimCommonSuffixes returns hostname with some common suffixes removed.
func TrimSuffix ¶ added in v1.6.0
TrimSuffix trims any trailing dots from a name and removes the suffix ending if present. The name will never be returned with a trailing dot, even after trimming.
func ValidHostname ¶ added in v1.40.0
ValidHostname checks if a string is a valid hostname.
func ValidLabel ¶ added in v1.38.0
ValidLabel reports whether label is a valid DNS label. All errors are vizerror.Error.
func ValidLabelLike ¶ added in v1.104.0
ValidLabelLike reports whether label contains DNS-valid characters only, adheres to a given maximum length, and starts and ends with a letter or number. For strict DNS-validity use ValidLabel. All errors are vizerror.Error.
Types ¶
type FQDN ¶ added in v1.8.0
type FQDN string
A FQDN is a fully-qualified DNS name or name suffix.
func ToFQDN ¶ added in v1.8.0
ToFQDN returns s as an FQDN, with a trailing dot added if missing. The empty string and "." both parse as ".".
Names containing whitespace or control characters are rejected. See the comment in the label loop below for why other characters are not validated.
func (FQDN) Parent ¶ added in v1.96.0
Parent returns the parent domain by stripping the first label. For "foo.bar.baz.", it returns "bar.baz." It returns an empty FQDN for root or single-label domains.
func (FQDN) WithTrailingDot ¶ added in v1.8.0
WithTrailingDot returns f as a string, with a trailing dot.
func (FQDN) WithoutTrailingDot ¶ added in v1.8.0
WithoutTrailingDot returns f as a string, with the trailing dot removed.