Documentation
¶
Overview ¶
Package storelimit is a rate limiter that keeps its counters in the Auth-All database. Two instances therefore share one count.
The limiter fails closed. It uses the database that sign-in uses, so a database failure fails sign-in anyway, and a fail-open limiter would only remove the bound at the worst moment.
Index ¶
- Constants
- func IPKey(raw string) string
- func Subject(scope ratelimit.Scope, k ratelimit.Key) string
- func Table(o schema.Options) schema.Table
- func Units(o schema.Options) ([]schema.Unit, error)
- type Limiter
- func (l *Limiter) Allow(ctx context.Context, k ratelimit.Key) (bool, error)
- func (l *Limiter) Cleanup(ctx context.Context, before time.Time) (int, error)
- func (l *Limiter) Decide(ctx context.Context, k ratelimit.Key) (ratelimit.Decision, error)
- func (l *Limiter) SchemaTables(o schema.Options) []schema.Table
- func (l *Limiter) SchemaUnits(o schema.Options) ([]schema.Unit, error)
- type Option
Constants ¶
const Owner = "ratelimit"
Owner names the owner of the counter table.
Variables ¶
This section is empty.
Functions ¶
func IPKey ¶
IPKey returns the counted address of one client address.
An IPv6 address counts per /64 block, because one customer owns a whole block. An IPv4-mapped address counts as the IPv4 address.
func Subject ¶
Subject returns the counted subject of one key in one scope. It returns an empty value when the key carries no subject of the scope.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter counts the attempts of every rule in the store.
func New ¶
New returns a limiter that keeps the counters of the rules in s.
The store must implement store.RateLimitCounter. Every first-party SQL store does.
func (*Limiter) Decide ¶
Decide implements ratelimit.Decider. Every rule of the operation counts the attempt, and the request fails when any rule is over its limit.
func (*Limiter) SchemaTables ¶
SchemaTables implements the schema contribution of a limiter.