-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
34 lines (27 loc) · 773 Bytes
/
options.go
File metadata and controls
34 lines (27 loc) · 773 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
package throttle
import "time"
// Option configures a limiter.
type Option interface {
apply(*options)
}
type options struct {
keyTTL time.Duration
clock func() time.Time
}
type optionFunc func(*options)
func (f optionFunc) apply(o *options) { f(o) }
// WithKeyTTL sets the duration for which the data structures associated with the limiter
// are held in Redis after they become inactive (expire).
// This is primarily used for testing purposes.
func WithKeyTTL(d time.Duration) Option {
return optionFunc(func(o *options) {
o.keyTTL = d
})
}
// WithClock sets a custom function to return the current time.
// This is primarily used for testing purposes.
func WithClock(f func() time.Time) Option {
return optionFunc(func(o *options) {
o.clock = f
})
}