domainname

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLabelLength = 63
	MaxLength      = 255
)

Variables

View Source
var ErrInvalidDomainName = errors.New("invalid domain name")
View Source
var Root = DomainName{}

Root is the zero-value, representing the root zone ".".

Functions

This section is empty.

Types

type DomainName

type DomainName struct {
	// contains filtered or unexported fields
}

DomainName is an immutable sequence of labels. Example: "www.example.com" -> ["www", "example", "com"]

func FromLabels

func FromLabels(labels []string) (DomainName, error)

FromLabels creates a DomainName from existing labels. It copies the slice to ensure immutability.

func FromString

func FromString(s string) (DomainName, error)

FromString creates a DomainName from a string (e.g., "www.example.com."). It automatically canonicalizes (lowercases) the name.

func (DomainName) AppendReversedTo added in v0.5.0

func (d DomainName) AppendReversedTo(dst []byte) []byte

AppendReversedTo appends the labels to the byte slice in REVERSE order separated by null bytes (0x00).

Input: "www.example.com" (labels: "www", "example", "com") Output: "com\0example\0www\0"

This is critical for BadgerDB Key sorting.

func (DomainName) DescendUntil

func (d DomainName) DescendUntil(stop DomainName, cb func(current DomainName) (bool, error)) error

DescendUntil calls the callback for each ancestor domain until the stop domain is reached.

func (DomainName) Equal

func (d DomainName) Equal(other DomainName) bool

Equal returns true if the domain names are identical.

func (DomainName) Fqdn

func (d DomainName) Fqdn() string

Fqdn returns the absolute domain name with trailing dot.

func (DomainName) IsRoot

func (d DomainName) IsRoot() bool

IsRoot returns true if this is the root domain ".".

func (DomainName) IsSubdomainOf

func (d DomainName) IsSubdomainOf(other DomainName) bool

IsSubdomainOf returns true if d is a child of other. "a.b.c" is subdomain of "b.c" -> true

func (DomainName) LabelCount added in v0.5.0

func (d DomainName) LabelCount() int

LabelCount returns the number of labels in the domain name.

func (DomainName) Labels

func (d DomainName) Labels() []string

Labels returns a copy of the domain name's labels. E.g., "www.example.com" -> ["www", "example", "com"]

func (DomainName) Parent

func (d DomainName) Parent() DomainName

Parent returns the parent domain. "www.example.com" -> "example.com" Root -> Root

func (DomainName) String

func (d DomainName) String() string

String returns the dotted representation (non-FQDN).

func (DomainName) Subdomain

func (d DomainName) Subdomain(label string) (DomainName, error)

Subdomain creates a child domain. "example.com".Subdomain("www") -> "www.example.com"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL