Versions in this module Expand all Collapse all v2 v2.52.0 Sep 21, 2026 v2.51.0 Sep 21, 2026 Changes in this version + const EndpointKey + var ErrInvalidName = errors.New("invalid limiter name") + var ErrInvalidRule = errors.New("invalid rule") + var ErrMissingStore = errors.New("store missing") + type Action string + const ActionLimit + const ActionLog + const ActionSkip + type CheckOption func(*checkOptions) + func WithCost(cost float64) CheckOption + func WithRuleContext(rctx RuleContext) CheckOption + type Config struct + Logger *slog.Logger + Name string + Registerer prometheus.Registerer + Rules []Rule + Store Store + type Evaluation struct + Exceeded bool + Info Info + func (e *Evaluation) Blocks() bool + func (e *Evaluation) Rule() Rule + type Identifier map[string]string + type Info struct + Count float64 + Limit int64 + Period time.Duration + Remaining float64 + ResetAt time.Time + type Limiter struct + func NewWithConfig(cfg *Config) (*Limiter, error) + func (l *Limiter) Check(ctx context.Context, id Identifier, opts ...CheckOption) *Result + func (l *Limiter) Clear(ctx context.Context, id Identifier) int64 + func (l *Limiter) Name() string + func (l *Limiter) Peek(ctx context.Context, id Identifier, opts ...CheckOption) *Result + type Matcher struct + func Eq(v string) Matcher + func OneOf(values ...string) Matcher + func Re(pattern string) Matcher + type Result struct + func (r *Result) Allowed() bool + func (r *Result) Blocked() bool + func (r *Result) Degraded() bool + func (r *Result) Evaluations() []Evaluation + func (r *Result) Exceeded() bool + func (r *Result) Failed() bool + func (r *Result) Info() *Info + func (r *Result) Matched() bool + func (r *Result) ResponseHeaders() map[string]string + func (r *Result) Rule() *Rule + func (r *Result) Skipped() bool + type Rule struct + Action Action + BanFor time.Duration + BanForFunc func(rctx RuleContext) time.Duration + Characteristics []string + CountDistinct string + Limit int64 + LimitFunc func(rctx RuleContext) int64 + Match map[string]Matcher + Name string + Period time.Duration + PeriodFunc func(rctx RuleContext) time.Duration + type RuleContext = any + type Store interface + Del func(ctx context.Context, keys ...string) (int64, error) + Eval func(ctx context.Context, script string, keys []string, args ...any) (any, error)