domain

package
v0.0.0-...-b067df3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package domain provides parsing and processing of IDNA2008 compliant domain names and DNS labels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Label

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

Label is a domain name label.

func ParseLabel

func ParseLabel(s string) (Label, error)

ParseLabel parses and validates a domain name label.

s is validated and canonicalized into the Unicode form suitable for use in domain registrations, as defined by IDNA2008.

func (Label) ASCIIString

func (l Label) ASCIIString() string

func (Label) AsTLD

func (l Label) AsTLD() Name

AsTLD returns the label as a top-level domain Name.

func (Label) Compare

func (l Label) Compare(m Label) int

Compare compares domain labels. It returns -1 if l < m, +1 if l > m, and 0 if l == m.

Compare returns 0 for labels that are equal as defined in IDNA2008. Unequal labels are ordered by lexical byte-wise comparison of their IDNA2008 canonical forms.

func (Label) Equal

func (l Label) Equal(m Label) bool

Equal reports whether domain labels are equal.

Equality is as defined in IDNA2008.

func (Label) String

func (l Label) String() string

type Name

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

Name is a fully qualified domain name.

A Name is always in valid, canonical Unicode form, according to the strictest ruleset for domain registration specified in IDNA2008 and Unicode Technical Standard #46.

func Parse

func Parse(s string) (Name, error)

Parse parses and validates a domain name string.

s is validated and canonicalized into the Unicode form suitable for use in domain registrations, as defined by IDNA2008.

func (Name) ASCIIString

func (d Name) ASCIIString() string

ASCIIString returns the domain name in its canonicalized ASCII (aka "punycode") form.

func (Name) AddPrefix

func (d Name) AddPrefix(labels ...Label) (Name, error)

AddPrefix returns d prefixed with labels.

For example, AddPrefix("qux", "bar") to "foo.com" is "qux.bar.foo.com".

func (Name) Compare

func (d Name) Compare(e Name) int

Compare compares domain names. It returns -1 if d < e, +1 if d > e, and 0 if d == e.

Compare returns 0 for domain names that are equal as defined in IDNA2008. Unequal domain names are ordered according to Label.Compare of their first unequal label, starting from the TLD.

func (Name) CutSuffix

func (d Name) CutSuffix(suffix Name) (rest []Label, found bool)

CutSuffix removes suffix from d. If d is a child domain of suffix, CutSuffix returns the remaining leaf labels and found=true. Otherwise, it returns nil, false.

func (Name) Equal

func (d Name) Equal(e Name) bool

Equal reports whether d and e are equal.

Equality is as defined in IDNA2008.

func (Name) Labels

func (d Name) Labels() []Label

Labels returns the individual labels of the domain name.

func (Name) MustAddPrefix

func (d Name) MustAddPrefix(labels ...Label) Name

MustAddPrefix is like AddPrefix, but panics if the formed prefix is invalid instead of returning an error.

func (Name) NumLabels

func (d Name) NumLabels() int

NumLabels returns the number of DNS labels in the domain name.

func (Name) String

func (d Name) String() string

String returns the domain name in its canonicalized PSL string format.

Jump to

Keyboard shortcuts

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