Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrUnexpectedScriptResult = errors.New("rateLimiter: unexpected backend result")
Functions ¶
func NewMockClock ¶
Types ¶
type Decision ¶
type Decision struct {
Allowed bool
RetryAfter time.Duration
BlockedUntil time.Time
Remaining int64
ResetAt time.Time
}
fixed window rate limiter
type FixedWindowBackend ¶
type FixedWindowBackend interface {
IncrWindow(ctx context.Context, baseKey string, window time.Duration, now time.Time) (count int64, resetAt time.Time, err error)
}
fixed window rate limiter
func NewMemoryStorage ¶
func NewMemoryStorage() FixedWindowBackend
func NewMemoryStorageWithShards ¶
func NewMemoryStorageWithShards(shards int) FixedWindowBackend
func NewRedisStorage ¶
func NewRedisStorage(client *redis.Client) FixedWindowBackend
type FixedWindowConfig ¶
fixed window rate limiter
type FixedWindowLimiter ¶
type FixedWindowLimiter struct {
// contains filtered or unexported fields
}
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
type RateLimiter ¶
fixed window rate limiter
func NewFixedWindowLimiter ¶
func NewFixedWindowLimiter(storage FixedWindowBackend, cfg FixedWindowConfig) RateLimiter
Click to show internal directories.
Click to hide internal directories.