-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
42 lines (34 loc) · 907 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package checkers
import (
"context"
"github.com/gocolly/colly"
"github.com/gocolly/colly/extensions"
"net/http"
"net/url"
)
// ProxyURL returns a proxy function (for use in a Transport)
// that always returns the same URL.
func ProxyURL(fixedURL *url.URL) func(*http.Request) (*url.URL, error) {
return func(pr *http.Request) (*url.URL, error) {
ctx := context.WithValue(pr.Context(), colly.ProxyURLKey, fixedURL.String())
*pr = *pr.WithContext(ctx)
return fixedURL, nil
}
}
func NewCollector(args *Wrapper) *colly.Collector {
// Instantiate default collector
c := colly.NewCollector(
colly.Async(true),
)
c.IgnoreRobotsTxt = true
c.AllowURLRevisit = true
c.CacheDir = ""
c.WithTransport(&http.Transport{
DisableKeepAlives: true,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 100,
})
c.SetRequestTimeout(args.TimeoutProxy)
extensions.RandomUserAgent(c)
return c
}