-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathratelimiter.go
More file actions
32 lines (26 loc) · 929 Bytes
/
ratelimiter.go
File metadata and controls
32 lines (26 loc) · 929 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
package checkpoint
import "time"
const (
BlockingPolicy = "blocking"
WaitingPolicy = "waiting"
)
// RateLimiterConfig defines the different limits that can be used across the rate limiter.
type RateLimiterConfig struct {
Limits []Limit
}
// Limit is the definition of one limit used by the rate limiter.
// multiple limits can be used in the same time and will all combinate.
// the associated for each policy defined the behaviour that will be applied if this limit is reached.
// If one of the limit is reached with the blocking policy, it will be prioritized compared to waiting ones.
type Limit struct {
Window time.Duration
Quantity int
Policy string
}
type RateLimiter struct {
config *RateLimiterConfig
}
// NewRateLimiter returns a RateLimiter pointer ater ensuring all the fields are correctly set and initialized.
func NewRateLimiter(cfg *RateLimiterConfig) (*RateLimiter, error) {
return nil, nil
}