-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
66 lines (56 loc) · 1.27 KB
/
config.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package wbot
import (
"runtime"
"time"
"github.com/twiny/poxa"
)
const (
defaultReferrer = "https://www.google.com/search"
defaultUserAgent = "WBot/v0.2.0 (+https://github.com/twiny/wbot)"
defaultTimeout = 10 * time.Second
defaultMaxBodySize = int64(1024 * 1024 * 5) // 5MB
)
type (
config struct {
parallel int
maxDepth int32
maxBodySize int64
timeout time.Duration
userAgents poxa.Spinner[string]
referrers poxa.Spinner[string]
proxies poxa.Spinner[string]
}
)
func newConfig(maxDepth int32, userAgents, referrers, proxies []string) *config {
if maxDepth <= 0 {
maxDepth = 10
}
var conf = &config{
parallel: runtime.NumCPU(),
maxDepth: maxDepth,
maxBodySize: defaultMaxBodySize,
timeout: defaultTimeout,
userAgents: poxa.NewSpinner(defaultUserAgent),
referrers: poxa.NewSpinner(defaultReferrer),
proxies: nil,
}
if len(userAgents) > 0 {
uaList := poxa.NewSpinner(userAgents...)
if uaList != nil {
conf.userAgents = uaList
}
}
if len(referrers) > 0 {
refList := poxa.NewSpinner(referrers...)
if refList != nil {
conf.referrers = refList
}
}
if len(proxies) > 0 {
proxyList := poxa.NewSpinner(proxies...)
if proxyList != nil {
conf.proxies = proxyList
}
}
return conf
}