Documentation
¶
Index ¶
- Constants
- Variables
- type DomainName
- func (d DomainName) AppendReversedTo(dst []byte) []byte
- func (d DomainName) DescendUntil(stop DomainName, cb func(current DomainName) (bool, error)) error
- func (d DomainName) Equal(other DomainName) bool
- func (d DomainName) Fqdn() string
- func (d DomainName) IsRoot() bool
- func (d DomainName) IsSubdomainOf(other DomainName) bool
- func (d DomainName) LabelCount() int
- func (d DomainName) Labels() []string
- func (d DomainName) Parent() DomainName
- func (d DomainName) String() string
- func (d DomainName) Subdomain(label string) (DomainName, error)
Constants ¶
const ( MaxLabelLength = 63 MaxLength = 255 )
Variables ¶
var ErrInvalidDomainName = errors.New("invalid domain name")
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"