Skip to content

Commit

Permalink
Quiet golint.
Browse files Browse the repository at this point in the history
  • Loading branch information
ayang64 committed Nov 22, 2017
1 parent d5b60ce commit 96398f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
25 changes: 13 additions & 12 deletions adstxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ import (
"strings"
)

// AdsTxt stores all of the data associated with an adx.txt file.
type AdsTxt struct {
Source string // URL of ads.txt file this represents.
Partner []Buyer
Variable map[string][]string
}

// Buyer encodes data assocated with one of the partners found in an ads.txt
// file.
type Buyer struct {
Domain string
PublisherID string
AccountType string
CertificationAuthority string
}

//
// Attempts to split a comma separated buyer record.
//
// Attempt to split a comma separated buyer record.
func (a *AdsTxt) parseBuyerRecord(line string) error {
// if we made it here, we should look for a comma separated list.
col := strings.Split(line, ",")
if len(col) != 3 && len(col) != 4 {
// Something is very wrong here.
return fmt.Errorf("Could not extract buyer records.")
return fmt.Errorf("could not extract buyer records")
}

if len(col) == 3 {
Expand Down Expand Up @@ -69,17 +70,19 @@ func (a *AdsTxt) parseVariable(line string) error {
return nil
}
}
return fmt.Errorf("Line does not conain a variable.")
return fmt.Errorf("line does not conain a variable")
}

// Parse parses the supplied adx.txt data and returns a packed AdsTxt
// structure.
func Parse(srcurl, txt string) (AdsTxt, error) {
rc := AdsTxt{
Source: srcurl,
Variable: make(map[string][]string),
}

if txt == "" {
return rc, fmt.Errorf("Given an empty string. Nothing to parse.")
return rc, fmt.Errorf("given an empty string; nothing to parse")
}

// create a scanner that reads line by line.
Expand Down Expand Up @@ -135,9 +138,10 @@ func fetch(url string, rc chan<- AdsTxt) {
rc <- a
}

// Fetch downloads and parses ads.txt files at each of the supplied URLs.
func Fetch(ctx context.Context, urls ...string) ([]AdsTxt, error) {
if len(urls) == 0 {
return nil, fmt.Errorf("No URLs supplied; nothing to do.")
return nil, fmt.Errorf("no URLs supplied; nothing to do")
}

ads := make(chan AdsTxt)
Expand All @@ -155,14 +159,11 @@ func Fetch(ctx context.Context, urls ...string) ([]AdsTxt, error) {
}
}()

for i := 0; true; {
// wait for respnses from each of the servers.
for i := 0; i < len(urls); i++ {
select {
case r := <-results:
ads <- r
i++
if i == len(urls) {
return
}
case <-ctx.Done():
// deadline reached.
return
Expand Down
10 changes: 2 additions & 8 deletions adstxt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ CONTACT=ayan@goosgoarch.com

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
a, err := Parse(test.Domain, test.Contents)
_, err := Parse(test.Domain, test.Contents)

if err != nil {
t.Fatalf("error: %v", err)
}

t.Logf("%#v", a)
})

}
Expand Down Expand Up @@ -119,7 +117,7 @@ func TestFetchURL(t *testing.T) {
"http://marry-xoxo.com/ads.txt",
}

ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 350*time.Millisecond)
defer cancel()

srcmap := make(map[string]struct{})
Expand All @@ -134,10 +132,6 @@ func TestFetchURL(t *testing.T) {
t.Logf("error: %s", err)
}

for i := range ads {
t.Logf("ads: %#v", ads[i])
}

for i := range ads {
delete(srcmap, ads[i].Source)
}
Expand Down

0 comments on commit 96398f8

Please # to comment.