-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
46 lines (38 loc) · 990 Bytes
/
options.go
File metadata and controls
46 lines (38 loc) · 990 Bytes
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
package botrate
import (
"time"
"github.com/cnlangzi/knownbots"
"golang.org/x/time/rate"
)
// Option is a functional option for configuring Limiter.
type Option func(*Limiter)
// WithLimit sets events per second for rate limiting.
func WithLimit(limit rate.Limit) Option {
return func(l *Limiter) {
l.cfg.Limit = limit
}
}
// WithAnalyzerWindow sets analysis window duration.
func WithAnalyzerWindow(window time.Duration) Option {
return func(l *Limiter) {
l.cfg.Window = window
}
}
// WithAnalyzerPageThreshold sets max distinct pages threshold.
func WithAnalyzerPageThreshold(threshold int) Option {
return func(l *Limiter) {
l.cfg.PageThreshold = threshold
}
}
// WithAnalyzerQueueCap sets event queue capacity.
func WithAnalyzerQueueCap(cap int) Option {
return func(l *Limiter) {
l.cfg.QueueCap = cap
}
}
// WithKnownbots implants a custom knownbots.Validator.
func WithKnownbots(kb *knownbots.Validator) Option {
return func(l *Limiter) {
l.kb = kb
}
}