Skip to content

Commit

Permalink
fix time.Parse for br, co.ua and pp.ua + "gofmt -w whois.go" (#7)
Browse files Browse the repository at this point in the history
* fix time.Parse for br, co.ua and pp.ua

* add tests

* Update whois.go

* Update whois.go

---------

Co-authored-by: beliy <[email protected]>
Co-authored-by: TwiN <[email protected]>
  • Loading branch information
3 people authored Jun 28, 2023
1 parent ea4c6db commit 9ff5df5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
30 changes: 20 additions & 10 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 @@ -47,18 +47,20 @@ func (c *Client) WithReferralCache(enabled bool) *Client {
"org": "whois.publicinterestregistry.org",
"red": "whois.nic.red",
"sh": "whois.nic.sh",
"co.ua": "whois.ua",
"pp.ua": "whois.ua",
}
}
return c
}

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,10 +137,18 @@ 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))
} else if strings.Contains(key, "domain status") {
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))
}
} else if strings.Contains(key, "status") {
response.DomainStatuses = append(response.DomainStatuses, value)
} else if strings.Contains(key, "name server") {
} else if (strings.Contains(key, "name server") || strings.Contains(key, "nserver")) {
response.NameServers = append(response.NameServers, value)
}
}
Expand Down
12 changes: 12 additions & 0 deletions whois_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ func TestClient(t *testing.T) {
domain: "name.de",
wantErr: true,
},
{
domain: "google.com.br",
wantErr: false,
},
{
domain: "xyz.co.ua",
wantErr: false,
},
{
domain: "xyz.pp.ua",
wantErr: false,
},
}
client := NewClient().WithReferralCache(true)
for _, scenario := range scenarios {
Expand Down

0 comments on commit 9ff5df5

Please sign in to comment.