package dnsname
import "tailscale.com/util/dnsname"
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
- type FQDN
Functions ¶
func FirstLabel ¶
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 ¶
NumLabels returns the number of DNS labels in hostname. If hostname is empty or the top-level name ".", returns 0.
func SanitizeHostname ¶
SanitizeHostname turns hostname into a valid name label according to RFC 1035.
func SanitizeLabel ¶
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 ¶
TrimCommonSuffixes returns hostname with some common suffixes removed.
func TrimSuffix ¶
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 ¶
ValidHostname checks if a string is a valid hostname.
func ValidLabel ¶
ValidLabel reports whether label is a valid DNS label. All errors are vizerror.Error.
Types ¶
type FQDN ¶
type FQDN string
A FQDN is a fully-qualified DNS name or name suffix.
func ToFQDN ¶
func (FQDN) Contains ¶
func (FQDN) NumLabels ¶
func (FQDN) WithTrailingDot ¶
WithTrailingDot returns f as a string, with a trailing dot.
func (FQDN) WithoutTrailingDot ¶
WithoutTrailingDot returns f as a string, with the trailing dot removed.
Source Files ¶
dnsname.go
- Version
- v1.84.1 (latest)
- Published
- May 29, 2025
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 2 days ago –
Tools for package owners.