-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoption.go
63 lines (59 loc) · 1.21 KB
/
option.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
package wbot
import (
"github.com/rs/zerolog"
"github.com/twiny/poxa"
"github.com/twiny/wbot/pkg/api"
)
type (
Option func(c *Crawler)
)
func WithParallel(parallel int) Option {
return func(c *Crawler) {
c.cfg.parallel = parallel
}
}
func WithMaxDepth(maxDepth int32) Option {
return func(c *Crawler) {
c.cfg.maxDepth = maxDepth
}
}
func WithUserAgents(userAgents []string) Option {
return func(c *Crawler) {
c.cfg.userAgents = poxa.NewSpinner(userAgents...)
}
}
func WithProxies(proxies []string) Option {
return func(c *Crawler) {
c.cfg.proxies = poxa.NewSpinner(proxies...)
}
}
func WithRateLimit(rates ...*api.RateLimit) Option {
return func(c *Crawler) {
c.limiter = newRateLimiter(rates...)
}
}
func WithFilter(rules ...*api.FilterRule) Option {
return func(c *Crawler) {
c.filter = newFilter(rules...)
}
}
func WithFetcher(fetcher api.Fetcher) Option {
return func(c *Crawler) {
c.fetcher = fetcher
}
}
func WithStore(store api.Store) Option {
return func(c *Crawler) {
c.store = store
}
}
func WithQueue(queue api.Queue) Option {
return func(c *Crawler) {
c.queue = queue
}
}
func WithLogLevel(level zerolog.Level) Option {
return func(c *Crawler) {
c.logger = c.logger.Level(level)
}
}