From ee088c60b6b7cc299fa4b56fac2a05e2bfe6a30b Mon Sep 17 00:00:00 2001 From: t94j0 Date: Wed, 2 Aug 2017 12:11:21 -0400 Subject: [PATCH] Updated with non-broken CUI --- domain/check_domain.go | 15 +++++++-------- domain/domains_file.go | 1 + domain/domains_keywords.go | 3 +++ domain/purchase.go | 9 ++++++++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/domain/check_domain.go b/domain/check_domain.go index 73c966e..86e5cdd 100644 --- a/domain/check_domain.go +++ b/domain/check_domain.go @@ -16,9 +16,9 @@ import ( "github.com/spf13/viper" ) -// DomainCategorization is a struct that is returned by bluecoat when asked +// Categorization is a struct that is returned by bluecoat when asked // to classify a domain -type DomainCategorization struct { +type Categorization struct { // URL of domain URL string `json:"url"` // Error is returned if there is an error checking the domain @@ -73,10 +73,9 @@ func CheckDomain(domain string, client *http.Client) error { newDomain := NewDomain(domainURL.Host, categorization) newDomain.PromptPurchase() return nil - } else { - fmt.Println("Found:", cat.URL, "-", categorization) - return nil } + fmt.Println("Found:", cat.URL, "-", categorization) + return nil } default: return errors.New(cat.Error) @@ -85,8 +84,8 @@ func CheckDomain(domain string, client *http.Client) error { } // makeRequest makes a bluecoat domain categorization request and returns a -// DomainCategorization object -func makeRequest(domain, captcha string, client *http.Client) (*DomainCategorization, error) { +// Categorization object +func makeRequest(domain, captcha string, client *http.Client) (*Categorization, error) { // Set captcha if a captcha is specified v := url.Values{} if captcha != "" { @@ -114,7 +113,7 @@ func makeRequest(domain, captcha string, client *http.Client) (*DomainCategoriza return nil, err } - cat := &DomainCategorization{} + cat := &Categorization{} if err := json.NewDecoder(response.Body).Decode(cat); err != nil { fmt.Println(err) return nil, err diff --git a/domain/domains_file.go b/domain/domains_file.go index 15cf07d..7683c44 100644 --- a/domain/domains_file.go +++ b/domain/domains_file.go @@ -9,6 +9,7 @@ import ( "strings" ) +// ParseFile takes a path and runs every domain through the CheckDomain function func ParseFile(filePath string) error { file, err := ioutil.ReadFile(filePath) if err != nil { diff --git a/domain/domains_keywords.go b/domain/domains_keywords.go index 349d299..3fd345d 100644 --- a/domain/domains_keywords.go +++ b/domain/domains_keywords.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/viper" ) +// ExpiredDomain is returned from scraping expireddomains.com type ExpiredDomain struct { Site string Registrars string @@ -30,6 +31,8 @@ type ExpiredDomain struct { Status string } +// ParseKeywords takes a list of keywords and scrapes expireddomains.com for +// keywords and passes them into CheckDomain func ParseKeywords(keywords []string) error { pages := viper.GetInt("pages") keyword := strings.Join(keywords, " ") diff --git a/domain/purchase.go b/domain/purchase.go index dab5ae7..b15d0c3 100644 --- a/domain/purchase.go +++ b/domain/purchase.go @@ -65,7 +65,11 @@ func (d *Domain) PromptPurchase() { for { fmt.Printf("Choose an option: ") reader := bufio.NewReader(os.Stdin) - input, _ := reader.ReadString('\n') + input, err := reader.ReadString('\n') + if err != nil { + fmt.Fprintln(os.Stderr, err) + break + } input = strings.Trim(input, "\n") choice, err := strconv.Atoi(input) if err != nil { @@ -85,6 +89,9 @@ func (d *Domain) PromptPurchase() { fmt.Fprintln(os.Stderr, "Error purchasing domain:", err) break } + + fmt.Println("Success!") + break } fmt.Printf("\n\n") }