domain

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package domain provides helper functions for managing domain names

Index

Constants

This section is empty.

Variables

View Source
var RootDomain = Name{}

RootDomain is the internet root, i.e. "."

Not to be confused with root servers (root-servers.net) or apex domains, which are sometimes referred as root.

Functions

func Apex

func Apex(domain string) string

Apex returns the formatted apex domain part of the domain name

Returns empty string if the domain name is empty or invalid or an effective top level domain.

func Contains

func Contains(first, second string) bool

Contains indicates whether this domain matches another domains or is a parent of another domain

Returns false if either domain names are empty or invalid.

func EffectiveTLD

func EffectiveTLD(domain string) string

EffectiveTLD returns the effective top level domain part of the domain name

Returns empty string if the domain name is empty or invalid.

func FQDN

func FQDN(domain string) string

FQDN returns the fully-qualified domain name

Returns empty string if the domain name is empty or invalid.

func HasPublicSuffix

func HasPublicSuffix(domain string) bool

HasPublicSuffix returns whether the domain name is under the public suffix, under which Internet users can directly register names

Returns false if the domain name is not an apex or subdomain, or is invalid. The complete list of public eTLDs can be found at https://publicsuffix.org/

func IsApex

func IsApex(domain string) bool

IsApex returns whether the domain is an apex domain

Returns false if the domain name is empty or invalid.

func IsApexOrSubdomain

func IsApexOrSubdomain(domain string) bool

IsApexOrSubdomain returns whether the domain is an apex domain or a subdomain

Returns false if the domain name is empty, eTLD or invalid.

func IsDomainName

func IsDomainName(s string) bool

IsDomainName determines whether a string is a valid domain name

func IsEffectiveTLD

func IsEffectiveTLD(domain string) bool

IsEffectiveTLD returns whether the domain is an effective top level (public suffix) domain

Returns false if the domain name is empty or invalid.

func IsICANN

func IsICANN(domain string) bool

IsICANN returns whether the eTLD (public suffix) is managed by the Internet Corporation for Assigned Names and Numbers

Returns false if the domain name is empty, eTLD or invalid. The complete list of public eTLDs can be found at https://publicsuffix.org/

func IsImmediateSubdomainOf

func IsImmediateSubdomainOf(first, second string) bool

IsImmediateSubdomainOf indicates whether the first domain is an immediate subdomain of the second domain

Returns false if either domain names are empty or invalid.

func IsParentOf

func IsParentOf(first, second string) bool

IsParentOf indicates whether this domain matches another domain or is a parent of another domain

Returns false if either domain names are empty or invalid.

func IsSubdomainOf

func IsSubdomainOf(first, second string) bool

IsSubdomainOf indicates whether the first domain is a subdomain of the second domain

Returns false if either domain names are empty or invalid.

func Parent

func Parent(domain string) string

Parent returns the parent domain name

Returns empty string if the domain name is empty or invalid.

func Resolve

func Resolve(domain string) ([]net.IP, error)

Resolve resolves the domain to one of more IP addresses

Checks against reserved IP addresses, and returns an error if the domain name is invalid, or no IPs could be looked up, or one or more IPs are reserved.

func Resolves

func Resolves(domain string) bool

Resolves checks whether the domain can resolve to one or more IP addresses

Checks against reserved IP addresses, and returns an error if the domain name is invalid, or no IPs could be looked up, or one or more IPs are reserved.

func Sanitize

func Sanitize(domain string) string

Sanitize performs sanitization of a domain name by converting to IDN format and removing "*." and "@." prefixes

Returns empty string if the domain name is empty or invalid.

func Subdomain

func Subdomain(domain string) string

Subdomain returns the subdomain part of the domain name

Returns empty string if the domain name is empty or invalid.

func Validate

func Validate(s string) error

Validate determines whether a string is a valid domain name

Validation is based on the domain name definition specified in RFC 1034, following the recommended domain name syntax, which is matching the host name definition in RFC 952, extended in RFC 1123. Exception is allowing usage of '_' in labels as there are various such names in existence.

Types

type Name

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

Name holds a structured domain name

func Extract

func Extract(s string) (Name, error)

Extract extracts a domain name from the specified string

Supports hostname, hostname with port number, origins and URLs

func MustParse

func MustParse(s string) Name

MustParse parses the specified domain name and returns it in structured format

Removes wildcard ("*." and "@.") prefixes, and converts the name to IDN format. Panics if the domain name is empty or invalid.

func Parse

func Parse(s string) (Name, error)

Parse parses the specified domain name and returns it in structured format

Removes wildcard ("*." and "@.") prefixes, and converts the name to IDN format. Returns an error if the domain name is empty or invalid.

func (Name) Apex

func (n Name) Apex() Name

Apex returns the apex domain part of the domain name

func (Name) Contains

func (n Name) Contains(other Name) bool

Contains indicates whether this domain matches another domain or is a parent of another domain

func (Name) EffectiveTLD

func (n Name) EffectiveTLD() string

EffectiveTLD returns the effective top level domain (public suffix) part of the domain name

func (Name) FQDN

func (n Name) FQDN() string

FQDN returns the fully-qualified domain name

func (Name) HasPublicSuffix

func (n Name) HasPublicSuffix() bool

HasPublicSuffix returns whether the domain name is under the public suffix, under which Internet users can directly register names

The public suffix eTLDs themselves are not considered public, hence this only applies to apex and subdomains. The complete list of public eTLDs can be found at https://publicsuffix.org/

func (Name) IsApex

func (n Name) IsApex() bool

IsApex returns whether the domain is an apex domain

func (Name) IsApexOrSubdomain

func (n Name) IsApexOrSubdomain() bool

IsApexOrSubdomain returns whether the domain is an apex domain or a subdomain

func (Name) IsEffectiveTLD

func (n Name) IsEffectiveTLD() bool

IsEffectiveTLD returns whether the domain is an effective top level (public suffix) domain

func (Name) IsICANN

func (n Name) IsICANN() bool

IsICANN returns whether the eTLD (public suffix) is managed by the Internet Corporation for Assigned Names and Numbers

The complete list of ICANN eTLDs can be found at https://publicsuffix.org/

func (Name) IsImmediateSubdomainOf

func (n Name) IsImmediateSubdomainOf(other Name) bool

IsImmediateSubdomainOf indicates whether this domain is an immediate subdomain of another domain

func (Name) IsParentOf

func (n Name) IsParentOf(other Name) bool

IsParentOf indicates whether this domain is a parent of another domain

func (Name) IsSubdomainOf

func (n Name) IsSubdomainOf(other Name) bool

IsSubdomainOf indicates whether this domain is a subdomain of another domain

func (Name) Parent

func (n Name) Parent() Name

Parent returns the parent domain name

func (Name) String

func (n Name) String() string

String returns the domain as a string

func (Name) Subdomain

func (n Name) Subdomain() string

Subdomain returns the subdomain part of the domain name

func (Name) Unicode

func (n Name) Unicode() string

Unicode returns the domain in Unicode format

Jump to

Keyboard shortcuts

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