Skip to content

Commit

Permalink
refactor: scope page counter to pagination loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lavafroth committed Jul 14, 2023
1 parent 674f69e commit 04528bb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pkg/providers/urlscan/urlscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ func (c *Client) Fetch(ctx context.Context, domain string, results chan string)
header.Value = c.config.URLScan.APIKey
}

page := 0
paginate:
for {
for page := 0; ; page++ {
select {
case <-ctx.Done():
break paginate
Expand All @@ -65,7 +64,7 @@ paginate:
// rate limited
if result.Status == 429 {
if c.config.Verbose {
logrus.WithField("provider", "urlscan").Warnf("urlscan responded with 429")
logrus.WithField("provider", "urlscan").Warnf("urlscan responded with 429, probably being rate limited")
}
break paginate
}
Expand All @@ -89,18 +88,17 @@ paginate:
if !result.HasMore {
break paginate
}
page++
}
}
return nil
}

func (c *Client) formatURL(domain string, after string) string {
if after != "" {
return fmt.Sprintf(_BaseURL+"api/v1/search/?q=domain:%s&size=100", domain) + "&search_after=" + after
after = "&search_after=" + after
}

return fmt.Sprintf(_BaseURL+"api/v1/search/?q=domain:%s&size=100", domain)
return fmt.Sprintf(_BaseURL+"api/v1/search/?q=domain:%s&size=100", domain) + after
}

func setBaseURL(baseURL string) {
Expand Down

0 comments on commit 04528bb

Please sign in to comment.