Documentation
¶
Index ¶
- Constants
- Variables
- func Domain(name string) (string, error)
- func DomainFromListWithOptions(l *List, name string, options *FindOptions) (string, error)
- func EffectiveTLDPlusOne(domain string) (string, error)
- func ExtraUrls(html string) []string
- func GetAllDomain(url string) []string
- func GetAllDomainByProxy(proxyUrl, requestUrl string) []string
- func GetAllUrl(url string) []string
- func GetAllUrlByProxy(proxyUrl, requestUrl string) []string
- func GetDomain(url string) (string, error)
- func GetMainDomain(input string) (string, error)
- func GetShortURL(longURL string) (string, error)
- func GetTopUrl(url string) string
- func Labels(name string) []string
- func PublicSuffix(domain string) (publicSuffix string, icann bool)
- func ToASCII(s string) (string, error)
- func ToUnicode(s string) (string, error)
- type DomainName
- func GetAllDomainInfo(url string) []*DomainName
- func GetAllDomainInfoByProxy(proxyUrl, requestUrl string) []*DomainName
- func GetDomainInfo(url string) (*DomainName, error)
- func Parse(name string) (*DomainName, error)
- func ParseFromListWithOptions(l *List, name string, options *FindOptions) (*DomainName, error)
- type FindOptions
- type Generator
- type List
- func (l *List) AddRule(r *Rule) error
- func (l *List) Find(name string, options *FindOptions) *Rule
- func (l *List) Load(r io.Reader, options *ParserOption) ([]Rule, error)
- func (l *List) LoadFile(path string, options *ParserOption) ([]Rule, error)
- func (l *List) LoadString(src string, options *ParserOption) ([]Rule, error)
- func (l *List) Size() int
- type ParserOption
- type Rule
- type ShortResponse
Constants ¶
const ( // Version identifies the current library version. // This is a pro forma convention given that Go dependencies // tends to be fetched directly from the repo. Version = "0.30.2" // NormalType represents a normal rule such as "com" NormalType = 1 // WildcardType represents a wildcard rule such as "*.com" WildcardType = 2 // ExceptionType represents an exception to a wildard rule ExceptionType = 3 )
const ListVersion = "PSL version 53b3d9 (Wed Apr 10 13:48:55 2024)"
Variables ¶
var CookieJarList cookiejar.PublicSuffixList = cookiejarList{DefaultList}
CookieJarList implements the cookiejar.PublicSuffixList interface.
var DefaultFindOptions = &FindOptions{IgnorePrivate: false, DefaultRule: DefaultRule}
DefaultFindOptions are the default options used to perform the lookup of rules in the list.
var DefaultList = NewList()
DefaultList is the default List and it is used by Parse and Domain.
var DefaultParserOptions = &ParserOption{PrivateDomains: true, ASCIIEncoded: false}
DefaultParserOptions are the default options used to parse a Public Suffix list.
var DefaultRule = MustNewRule("*")
DefaultRule is the default Rule that represents "*".
Functions ¶
func Domain ¶
Domain extract and return the domain name from the input using the default (Public Suffix) List.
Examples:
publicsuffix.Domain("example.com")
// example.com
publicsuffix.Domain("www.example.com")
// example.com
publicsuffix.Domain("www.example.co.uk")
// example.co.uk
func DomainFromListWithOptions ¶
func DomainFromListWithOptions(l *List, name string, options *FindOptions) (string, error)
DomainFromListWithOptions extract and return the domain name from the input using the (Public Suffix) list passed as argument.
Examples:
list := NewList() publicsuffix.DomainFromListWithOptions(list, "example.com") // example.com publicsuffix.DomainFromListWithOptions(list, "www.example.com") // example.com publicsuffix.DomainFromListWithOptions(list, "www.example.co.uk") // example.co.uk
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 GetAllDomain ¶
func GetAllDomainByProxy ¶
func GetAllUrlByProxy ¶
func GetMainDomain ¶ added in v0.2.9
GetMainDomain 输入任意子域名、URL或IP地址,返回其主域名或IP地址。 功能特性: 1. 准确提取主域名:自动处理多部分顶级域名,如 "google.co.uk"。 2. 支持IP地址:如果输入是IP地址(v4或v6),则直接返回该IP地址。 3. 支持中文域名:可以正确处理包含中文字符的国际化域名(IDN)。 4. 兼容完整URL:能从复杂的URL中提取出主机部分进行处理 示例: - "deep.learning.google.co.uk" -> "google.co.uk" - "http://192.168.1.1:8080/path" -> "192.168.1.1" - "邮件.宁波舟山港.net" -> "宁波舟山港.net"
func GetShortURL ¶ added in v0.1.9
GetShortURL https://www.free-api.com/doc/300
func Labels ¶
Labels decomposes given domain name into labels, corresponding to the dot-separated tokens.
func PublicSuffix ¶
PublicSuffix returns the public suffix of the domain using a copy of the publicsuffix.org database packaged into this library.
Note. To maintain compatibility with the golang.org/x/net/publicsuffix this method doesn't return an error. However, in case of error, the returned value is empty.
func ToASCII ¶
ToASCII is a wrapper for idna.ToASCII.
This wrapper exists because idna.ToASCII backward-compatibility was broken twice in few months and I can't call this package directly anymore. The wrapper performs some terrible-but-necessary before-after replacements to make sure an already ASCII input always results in the same output even if passed through ToASCII.
See golang/net@67957fd0b1, golang/net@f2499483f9, golang/net@78ebe5c8b6, and weppos/publicsuffix-go#66.
Types ¶
type DomainName ¶
DomainName represents a domain name.
func GetAllDomainInfo ¶
func GetAllDomainInfo(url string) []*DomainName
func GetAllDomainInfoByProxy ¶
func GetAllDomainInfoByProxy(proxyUrl, requestUrl string) []*DomainName
func GetDomainInfo ¶
func GetDomainInfo(url string) (*DomainName, error)
func Parse ¶
func Parse(name string) (*DomainName, error)
Parse decomposes the name into TLD, SLD, TRD using the default (Public Suffix) List, and returns the result as a DomainName
Examples:
list := NewList()
publicsuffix.Parse("example.com")
// &DomainName{"com", "example"}
publicsuffix.Parse("www.example.com")
// &DomainName{"com", "example", "www"}
publicsuffix.Parse("www.example.co.uk")
// &DomainName{"co.uk", "example"}
func ParseFromListWithOptions ¶
func ParseFromListWithOptions(l *List, name string, options *FindOptions) (*DomainName, error)
ParseFromListWithOptions decomposes the name into TLD, SLD, TRD using the (Public Suffix) list passed as argument, and returns the result as a DomainName
Examples:
list := NewList()
publicsuffix.ParseFromListWithOptions(list, "example.com")
// &DomainName{"com", "example"}
publicsuffix.ParseFromListWithOptions(list, "www.example.com")
// &DomainName{"com", "example", "www"}
publicsuffix.ParseFromListWithOptions(list, "www.example.co.uk")
// &DomainName{"co.uk", "example"}
func (*DomainName) String ¶
func (d *DomainName) String() string
String joins the components of the domain name into a single string. Empty labels are skipped.
Examples:
DomainName{"com", "example"}.String()
// example.com
DomainName{"com", "example", "www"}.String()
// www.example.com
type FindOptions ¶
type FindOptions struct {
// Set to true to ignore the rules within the "Private" section of the Public Suffix List.
IgnorePrivate bool
// The default rule to use when no rule matches the input.
// The format Public Suffix algorithm states that the rule "*" should be used when no other rule matches,
// but some consumers may have different needs.
DefaultRule *Rule
}
FindOptions are the options you can use to customize the way a Rule is searched within the list.
type Generator ¶ added in v0.1.8
type Generator struct {
Verbose bool
}
Generator represents a generator.
func NewGenerator ¶ added in v0.1.8
func NewGenerator() *Generator
NewGenerator creates a Generator with default settings.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents a Public Suffix List.
func NewListFromFile ¶
func NewListFromFile(path string, options *ParserOption) (*List, error)
NewListFromFile parses a string that represents a Public Suffix source and returns a List initialized with the rules in the source.
func NewListFromString ¶
func NewListFromString(src string, options *ParserOption) (*List, error)
NewListFromString parses a string that represents a Public Suffix source and returns a List initialized with the rules in the source.
func (*List) AddRule ¶
AddRule adds a new rule to the list.
The exact position of the rule into the list is unpredictable. The list may be optimized internally for lookups, therefore the algorithm will decide the best position for the new rule.
func (*List) Find ¶
func (l *List) Find(name string, options *FindOptions) *Rule
Find and returns the most appropriate rule for the domain name.
func (*List) LoadFile ¶
func (l *List) LoadFile(path string, options *ParserOption) ([]Rule, error)
LoadFile parses and loads a set of rules from a File into the current list.
func (*List) LoadString ¶
func (l *List) LoadString(src string, options *ParserOption) ([]Rule, error)
LoadString parses and loads a set of rules from a String into the current list.
type ParserOption ¶
type ParserOption struct {
// Set to false to skip the private domains when parsing.
// Default to true, which means the private domains are included.
PrivateDomains bool
// Set to false if the input is encoded in U-labels (Unicode)
// as opposite to A-labels.
// Default to false, which means the list is containing Unicode domains.
// This is the default because the original PSL currently contains Unicode.
ASCIIEncoded bool
}
ParserOption are the options you can use to customize the way a List is parsed from a file or a string.
type Rule ¶
Rule represents a single rule in a Public Suffix List.
func DefaultRules ¶
func DefaultRules() [9730]Rule
func MustNewRule ¶
MustNewRule is like NewRule, but panics if the content cannot be parsed.
func NewRule ¶
NewRule parses the rule content, creates and returns a Rule.
The content of the rule MUST be encoded in ASCII (A-labels).
func NewRuleUnicode ¶
NewRuleUnicode is like NewRule, but expects the content to be encoded in Unicode (U-labels).
func (*Rule) Decompose ¶
Decompose takes a name as input and decomposes it into a tuple of <TRD+SLD, TLD>, according to the rule definition and type.
func (*Rule) Match ¶
Match checks if the rule matches the name.
A domain name is said to match a rule if and only if all of the following conditions are met:
- When the domain and rule are split into corresponding labels, that the domain contains as many or more labels than the rule.
- Beginning with the right-most labels of both the domain and the rule, and continuing for all labels in the rule, one finds that for every pair, either they are identical, or that the label from the rule is "*".