Documentation
¶
Overview ¶
Package domain provides helper functions for managing domain names
Index ¶
- Variables
- func Apex(domain string) string
- func Contains(first, second string) bool
- func EffectiveTLD(domain string) string
- func FQDN(domain string) string
- func HasPublicSuffix(domain string) bool
- func IsApex(domain string) bool
- func IsApexOrSubdomain(domain string) bool
- func IsDomainName(s string) bool
- func IsEffectiveTLD(domain string) bool
- func IsICANN(domain string) bool
- func IsImmediateSubdomainOf(first, second string) bool
- func IsParentOf(first, second string) bool
- func IsSubdomainOf(first, second string) bool
- func Parent(domain string) string
- func Resolve(domain string) ([]net.IP, error)
- func Resolves(domain string) bool
- func Sanitize(domain string) string
- func Subdomain(domain string) string
- func Validate(s string) error
- type Name
- func (n Name) Apex() Name
- func (n Name) Contains(other Name) bool
- func (n Name) EffectiveTLD() string
- func (n Name) FQDN() string
- func (n Name) HasPublicSuffix() bool
- func (n Name) IsApex() bool
- func (n Name) IsApexOrSubdomain() bool
- func (n Name) IsEffectiveTLD() bool
- func (n Name) IsICANN() bool
- func (n Name) IsImmediateSubdomainOf(other Name) bool
- func (n Name) IsParentOf(other Name) bool
- func (n Name) IsSubdomainOf(other Name) bool
- func (n Name) Parent() Name
- func (n Name) String() string
- func (n Name) Subdomain() string
- func (n Name) Unicode() string
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
FQDN returns the fully-qualified domain name
Returns empty string if the domain name is empty or invalid.
func HasPublicSuffix ¶
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 ¶
IsApex returns whether the domain is an apex domain
Returns false if the domain name is empty or invalid.
func IsApexOrSubdomain ¶
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 ¶
IsDomainName determines whether a string is a valid domain name
func IsEffectiveTLD ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Parent returns the parent domain name
Returns empty string if the domain name is empty or invalid.
func Resolve ¶
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 ¶
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 ¶
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 ¶
Subdomain returns the subdomain part of the domain name
Returns empty string if the domain name is empty or invalid.
func Validate ¶
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 ¶
Extract extracts a domain name from the specified string
Supports hostname, hostname with port number, origins and URLs
func MustParse ¶
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 ¶
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) Contains ¶
Contains indicates whether this domain matches another domain or is a parent of another domain
func (Name) EffectiveTLD ¶
EffectiveTLD returns the effective top level domain (public suffix) part of the domain name
func (Name) HasPublicSuffix ¶
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) IsApexOrSubdomain ¶
IsApexOrSubdomain returns whether the domain is an apex domain or a subdomain
func (Name) IsEffectiveTLD ¶
IsEffectiveTLD returns whether the domain is an effective top level (public suffix) domain
func (Name) IsICANN ¶
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 ¶
IsImmediateSubdomainOf indicates whether this domain is an immediate subdomain of another domain
func (Name) IsParentOf ¶
IsParentOf indicates whether this domain is a parent of another domain
func (Name) IsSubdomainOf ¶
IsSubdomainOf indicates whether this domain is a subdomain of another domain