chore(deps): Update TwiN/whois to v1.1.0
This commit is contained in:
42
vendor/github.com/TwiN/whois/whois.go
generated
vendored
42
vendor/github.com/TwiN/whois/whois.go
generated
vendored
@ -13,16 +13,49 @@ const (
|
||||
|
||||
type Client struct {
|
||||
whoisServerAddress string
|
||||
|
||||
isCachingReferralWHOISServers bool
|
||||
referralWHOISServersCache map[string]string
|
||||
}
|
||||
|
||||
func NewClient() *Client {
|
||||
return &Client{
|
||||
whoisServerAddress: ianaWHOISServerAddress,
|
||||
whoisServerAddress: ianaWHOISServerAddress,
|
||||
referralWHOISServersCache: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func (c Client) Query(domain string) (string, error) {
|
||||
// WithReferralCache allows you to enable or disable the referral WHOIS server cache.
|
||||
// While ianaWHOISServerAddress is the "entry point" for WHOIS queries, it sometimes has
|
||||
// availability issues. One way to mitigate this is to cache the referral WHOIS server.
|
||||
//
|
||||
// This is disabled by default
|
||||
func (c *Client) WithReferralCache(enabled bool) *Client {
|
||||
c.isCachingReferralWHOISServers = enabled
|
||||
if enabled {
|
||||
// We'll set a couple of common ones right away to avoid unnecessary queries
|
||||
c.referralWHOISServersCache = map[string]string{
|
||||
"com": "whois.verisign-grs.com",
|
||||
"black": "whois.nic.black",
|
||||
"dev": "whois.nic.google",
|
||||
"green": "whois.nic.green",
|
||||
"io": "whois.nic.io",
|
||||
"net": "whois.verisign-grs.com",
|
||||
"org": "whois.publicinterestregistry.org",
|
||||
"red": "whois.nic.red",
|
||||
"sh": "whois.nic.sh",
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) Query(domain string) (string, error) {
|
||||
parts := strings.Split(domain, ".")
|
||||
if c.isCachingReferralWHOISServers {
|
||||
if cachedWHOISServer, ok := c.referralWHOISServersCache[domain]; ok {
|
||||
return c.query(cachedWHOISServer, domain)
|
||||
}
|
||||
}
|
||||
output, err := c.query(c.whoisServerAddress, parts[len(parts)-1])
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -32,6 +65,9 @@ func (c Client) Query(domain string) (string, error) {
|
||||
endIndex := strings.Index(output[startIndex:], "\n") + startIndex
|
||||
whois := strings.TrimSpace(output[startIndex:endIndex])
|
||||
if referOutput, err := c.query(whois+":43", domain); err == nil {
|
||||
if c.isCachingReferralWHOISServers {
|
||||
c.referralWHOISServersCache[domain] = whois + ":43"
|
||||
}
|
||||
return referOutput, nil
|
||||
}
|
||||
return "", err
|
||||
@ -45,7 +81,7 @@ func (c Client) query(whoisServerAddress, domain string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
defer connection.Close()
|
||||
connection.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
_ = connection.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
_, err = connection.Write([]byte(domain + "\r\n"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
Reference in New Issue
Block a user