@@ -29,7 +29,6 @@ type Client struct {
29
29
}
30
30
31
31
func New (c * providers.Config , filters providers.Filters ) (* Client , error ) {
32
- client := & Client {config : c , filters : filters }
33
32
// Fetch the list of available CommonCrawl Api URLs.
34
33
resp , err := httpclient .MakeRequest (c .Client , "http://index.commoncrawl.org/collinfo.json" , c .MaxRetries , c .Timeout )
35
34
if err != nil {
@@ -45,8 +44,7 @@ func New(c *providers.Config, filters providers.Filters) (*Client, error) {
45
44
return nil , errors .New ("failed to grab latest commoncrawl index" )
46
45
}
47
46
48
- client .apiURL = r [0 ].API
49
- return client , nil
47
+ return & Client {config : c , filters : filters , apiURL : r [0 ].API }, nil
50
48
}
51
49
52
50
func (c * Client ) Name () string {
@@ -62,9 +60,7 @@ func (c *Client) Fetch(ctx context.Context, domain string, results chan string)
62
60
}
63
61
// 0 pages means no results
64
62
if p .Pages == 0 {
65
- if c .config .Verbose {
66
- logrus .WithFields (logrus.Fields {"provider" : Name }).Infof ("no results for %s" , domain )
67
- }
63
+ logrus .WithFields (logrus.Fields {"provider" : Name }).Infof ("no results for %s" , domain )
68
64
return nil
69
65
}
70
66
@@ -74,9 +70,7 @@ paginate:
74
70
case <- ctx .Done ():
75
71
break paginate
76
72
default :
77
- if c .config .Verbose {
78
- logrus .WithFields (logrus.Fields {"provider" : Name , "page" : page }).Infof ("fetching %s" , domain )
79
- }
73
+ logrus .WithFields (logrus.Fields {"provider" : Name , "page" : page }).Infof ("fetching %s" , domain )
80
74
apiURL := c .formatURL (domain , page )
81
75
resp , err := httpclient .MakeRequest (c .config .Client , apiURL , c .config .MaxRetries , c .config .Timeout )
82
76
if err != nil {
@@ -111,18 +105,15 @@ func (c *Client) formatURL(domain string, page uint) string {
111
105
}
112
106
113
107
// Fetch the number of pages.
114
- func (c * Client ) getPagination (domain string ) (paginationResult , error ) {
108
+ func (c * Client ) getPagination (domain string ) (r paginationResult , err error ) {
115
109
url := fmt .Sprintf ("%s&showNumPages=true" , c .formatURL (domain , 0 ))
110
+ var resp []byte
116
111
117
- resp , err : = httpclient .MakeRequest (c .config .Client , url , c .config .MaxRetries , c .config .Timeout )
112
+ resp , err = httpclient .MakeRequest (c .config .Client , url , c .config .MaxRetries , c .config .Timeout )
118
113
if err != nil {
119
- return paginationResult {}, err
120
- }
121
-
122
- var r paginationResult
123
- if err = jsoniter .Unmarshal (resp , & r ); err != nil {
124
- return r , err
114
+ return
125
115
}
126
116
127
- return r , nil
117
+ err = jsoniter .Unmarshal (resp , & r )
118
+ return
128
119
}
0 commit comments