Documentation ¶
Overview ¶
Package publicsuffix provides functions to query the public suffix list found at:
https://publicsuffix.org/
When first initialised, this library uses a statically compiled list which may be out of date - callers should use Update to attempt to fetch a new version from the official GitHub repository. Alternate data sources (such as a network share, etc) can be used by implementing the ListRetriever interface.
A list can be serialised using Write, and loaded using Read - this allows the caller to write the updated internal list to disk at shutdown and resume using it immediately on the next start.
All exported functions are concurrency safe and the internal list uses copy-on-write during updates to avoid blocking queries.
Example ¶
// Update to get the latest version of the Public Suffix List from the github repository if err := Update(); err != nil { panic(err.Error()) } // Check the list version var release = Release() fmt.Printf("Public Suffix List release: %s", release) // Check if a given domain is in the Public Suffix List if HasPublicSuffix("example.domain.com") { // Do something } // Get public suffix var suffix, icann = PublicSuffix("another.example.domain.com") fmt.Printf("suffix: %s, icann: %v", suffix, icann) // Write the current Public List to a file var file, err = os.Create("list_backup") if err != nil { panic(err.Error()) } defer file.Close() if err := Write(file); err != nil { panic(err.Error()) } // Read and load a list from a file file, err = os.Open("list_backup") if err != nil { panic(err.Error()) } defer file.Close() if err := Read(file); err != nil { panic(err.Error()) }
Output:
Index ¶
- Variables
- func EffectiveTLDPlusOne(domain string) (string, error)
- func HasPublicSuffix(domain string) bool
- func PublicSuffix(domain string) (string, bool)
- func Read(r io.Reader) error
- func Release() string
- func Update() error
- func UpdateWithListRetriever(listRetriever ListRetriever) error
- func Write(w io.Writer) error
- type ListRetriever
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var CookieJarList cookiejar.PublicSuffixList = list{}
CookieJarList implements the cookiejar.PublicSuffixList interface by calling the PublicSuffix function.
Functions ¶
func EffectiveTLDPlusOne ¶
EffectiveTLDPlusOne returns the effective top level domain plus one more label. For example, the eTLD+1 for "foo.bar.golang.org" is "golang.org".
func HasPublicSuffix ¶
HasPublicSuffix returns true if the TLD of domain is in the public suffix list.
func PublicSuffix ¶
PublicSuffix returns the public suffix of the domain using a copy of the internal public suffix list.
The returned bool is true when the public suffix is managed by the Internet Corporation for Assigned Names and Numbers. If false, the public suffix is privately managed. For example, foo.org and foo.co.uk are ICANN domains, foo.dyndns.org and foo.blogspot.co.uk are private domains.
func Read ¶
Read loads a public suffix list serialised and compressed by Write and uses it for future lookups.
func Release ¶
func Release() string
Release returns the release of the current internal public suffix list.
func Update ¶
func Update() error
Update fetches the latest public suffix list from the official github repository and uses it for future lookups.
https://github.com/publicsuffix/list
func UpdateWithListRetriever ¶
func UpdateWithListRetriever(listRetriever ListRetriever) error
UpdateWithListRetriever attempts to update the internal public suffix list using listRetriever as a data source.
UpdateWithListRetriever is provided to allow callers to provide custom update sources, such as reading from a network store or local cache instead of fetching from the GitHub repository.
Types ¶
type ListRetriever ¶
type ListRetriever interface { GetLatestReleaseTag() (string, error) GetList(release string) (io.Reader, error) }
ListRetriever is the interface for retrieving release information/content
func NewGitHubListRetriever ¶
func NewGitHubListRetriever(client *http.Client) ListRetriever
NewGitHubListRetriever creates a new ListRetriever with a custom HTTP client.