Documentation
¶
Overview ¶
Package ratelimit admits events per key against one or more sliding windows ("at most Limit in any Per"), in process or shared through Redis (or Garnet). Both stores keep the same log of admitted event times, so a limit and its retry time mean the same thing with and without Redis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter admits events from per-key allowances.
type Options ¶
type Options struct {
Windows []Window // an event must fit every one
// Redis shares the log across replicas; nil keeps it per process.
Redis redis.UniversalClient
Prefix string // Redis key prefix
// Errors counts Redis failures; each is served by the per-process log.
Errors *expvar.Int
Logger *slog.Logger
Now func() time.Time // default time.Now
}
Options configure a Limiter.
Click to show internal directories.
Click to hide internal directories.