tailscale.comtailscale.com/util/dnsname Index | Files

package dnsname

import "tailscale.com/util/dnsname"

Package dnsname contains string functions for working with DNS names.

Index

Functions

func FirstLabel

func FirstLabel(hostname string) string

FirstLabel returns the first DNS label of hostname.

func HasSuffix

func HasSuffix(name, suffix string) bool

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

func NumLabels(hostname string) int

NumLabels returns the number of DNS labels in hostname. If hostname is empty or the top-level name ".", returns 0.

func SanitizeHostname

func SanitizeHostname(hostname string) string

SanitizeHostname turns hostname into a valid name label according to RFC 1035.

func SanitizeLabel

func SanitizeLabel(label string) string

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

func TrimCommonSuffixes(hostname string) string

TrimCommonSuffixes returns hostname with some common suffixes removed.

func TrimSuffix

func TrimSuffix(name, suffix string) string

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

func ValidHostname(hostname string) error

ValidHostname checks if a string is a valid hostname.

func ValidLabel

func ValidLabel(label string) error

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 ToFQDN(s string) (FQDN, error)

func (FQDN) Contains

func (f FQDN) Contains(other FQDN) bool

func (FQDN) NumLabels

func (f FQDN) NumLabels() int

func (FQDN) WithTrailingDot

func (f FQDN) WithTrailingDot() string

WithTrailingDot returns f as a string, with a trailing dot.

func (FQDN) WithoutTrailingDot

func (f FQDN) WithoutTrailingDot() string

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.