Documentation
¶
Overview ¶
Package securitylimit provides the shared backend for security-sensitive limits.
Index ¶
- Constants
- type Bucket
- type Decision
- type Limiter
- type Memory
- func (m *Memory) Peek(ctx context.Context, spec Window, key string) (Decision, error)
- func (m *Memory) Record(ctx context.Context, spec Window, key string) (Decision, error)
- func (m *Memory) RecordN(ctx context.Context, spec Window, key string, n int) (Decision, error)
- func (m *Memory) Reset(ctx context.Context, spec Window, key string) error
- func (m *Memory) Size(name string) int
- func (m *Memory) Take(ctx context.Context, spec Bucket, key string) (Decision, error)
- func (m *Memory) UndoN(ctx context.Context, spec Window, key string, n int, windowStart time.Time) error
- type Window
Constants ¶
const DefaultMaxKeysPerName = 8192
DefaultMaxKeysPerName is the per-name cap used when NewMemory gets no positive cap.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decision ¶
type Decision struct {
Allowed bool
RetryAfter time.Duration
Remaining int
First bool
WindowStart time.Time
}
Decision describes a limiter operation. First is set on the first request that reaches a window limit, so callers can report that lockout once.
type Limiter ¶
type Limiter interface {
Take(ctx context.Context, b Bucket, key string) (Decision, error)
Peek(ctx context.Context, w Window, key string) (Decision, error)
Record(ctx context.Context, w Window, key string) (Decision, error)
// RecordN atomically reserves n successful units when all of them fit in the window and returns that window's start.
RecordN(ctx context.Context, w Window, key string, n int) (Decision, error)
// UndoN refunds a reservation only if its original window is still current.
UndoN(ctx context.Context, w Window, key string, n int, windowStart time.Time) error
Reset(ctx context.Context, w Window, key string) error
}
Limiter covers token buckets and bounded failure windows used by security checks.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is the VPS implementation. Names isolate each limiter's key space.
func NewMemory ¶
NewMemory returns an in-memory limiter with the production clock and key cap when the corresponding arguments are nil or non-positive.
func (*Memory) RecordN ¶
RecordN reserves n successful units atomically. Unlike Record, it never records a partial reservation: callers can reject a whole operation before changing any users.