Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add support for *.ua TLDs and com.br #7

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
ianaWHOISServerAddress = "whois.iana.org:43"
)

var tldWithoutExpirationDate = []string{"at","be","ch","co.at","com.br","or.at","de","fr","me","mx","nl"}
var tldWithoutExpirationDate = []string{"at", "be", "ch", "co.at", "com.br", "or.at", "de", "fr", "me", "mx", "nl"}

type Client struct {
whoisServerAddress string
Expand Down Expand Up @@ -53,12 +53,12 @@ func (c *Client) WithReferralCache(enabled bool) *Client {
}

func doesTLDHaveExpirationDate(e string) bool {
for _, a := range tldWithoutExpirationDate {
if a == e {
return true
}
}
return false
for _, a := range tldWithoutExpirationDate {
if a == e {
return true
}
}
return false
}

func (c *Client) Query(domain string) (string, error) {
Expand Down Expand Up @@ -135,7 +135,15 @@ func (c Client) QueryAndParse(domain string) (*Response, error) {
key := strings.ToLower(strings.TrimSpace(line[:valueStartIndex]))
value := strings.TrimSpace(line[valueStartIndex+1:])
if response.ExpirationDate.Unix() != 0 && strings.Contains(key, "expir") && strings.Contains(key, "date") {
response.ExpirationDate, _ = time.Parse(time.RFC3339, strings.ToUpper(value))
switch {
case strings.HasSuffix(domain, ".br"):
response.ExpirationDate, _ = time.Parse("20060102", strings.ToUpper(value))
case strings.HasSuffix(domain, "co.ua"),
strings.HasSuffix(domain, "pp.ua"):
response.ExpirationDate, _ = time.Parse("02-Jan-2006 03:04:05 MST", strings.ToUpper(value))
default:
response.ExpirationDate, _ = time.Parse(time.RFC3339, strings.ToUpper(value))
}
TwiN marked this conversation as resolved.
Show resolved Hide resolved
} else if strings.Contains(key, "domain status") {
response.DomainStatuses = append(response.DomainStatuses, value)
} else if strings.Contains(key, "name server") {
Expand Down