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

Domain func must return an error on failure #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import (
func main() {
domain := "dreamdomain.io"

available := available.Domain(domain)
available, err := available.Domain(domain)
if err != nil {
panic(err)
}

if available {
fmt.Println("[+] Success!")
Expand Down
32 changes: 21 additions & 11 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ func SafeDomain(domain string) (available, badtld bool) {
}

if !badtld {
available = match(tld, getWhois(query))
whois, err := getWhois(query)
if err != nil {
return
}

available = match(tld, whois)
}
}

Expand All @@ -38,22 +43,27 @@ This function does not have a triage step, and will
result in testing each TLD with one of the default
responses.
*/
func Domain(domain string) (available bool) {
available = false

func Domain(domain string) (bool, error) {
domain = setDomain(domain)
tld, icann := publicsuffix.PublicSuffix(domain)

var available bool

if icann == true {
query, err := publicsuffix.EffectiveTLDPlusOne(domain)
if err != nil {
return
return false, err
}

available = match(tld, getWhois(query))
whois, err := getWhois(query)
if err != nil {
return false, err
}

available = match(tld, whois)
}

return available
return available, nil
}

func setDomain(domain string) string {
Expand Down Expand Up @@ -107,18 +117,18 @@ func match(tld, resp string) (available bool) {
}

// Makes whois request, returns resposne as string
func getWhois(domain string) (response string) {
func getWhois(domain string) (string, error) {
req, err := whois.NewRequest(domain)
if err != nil {
return
return "", err
}

resp, err := whois.DefaultClient.Fetch(req)
if err != nil {
return
return "", err
}

return fmt.Sprintf("%s", resp)
return fmt.Sprintf("%s", resp), nil
}

// Checks if the TLD is apart of our "bad tld" list
Expand Down