Documentation
¶
Overview ¶
Package quota implements a persisted, long-term traffic-volume limiter that can be shared across services by name. Unlike the rate limiters in limiter/traffic and limiter/rate, it accumulates total bytes within a window [startsAt, expiresAt) and stops the referencing service(s) once a byte limit is reached. Enforcement is fail-open outside the window.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrQuotaExceeded = errors.New("quota: traffic limit reached")
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
func NewLimiter ¶
type Options ¶
type Options struct {
Limit uint64
StartsAt time.Time
ExpiresAt time.Time
Direction Direction
Flush time.Duration
Store Store
Logger logger.Logger
}
Options seeds a Limiter. Limit and the window are config-authoritative; a persisted counter is restored only for a matching window (see NewLimiter).
type RedisConfig ¶
type Store ¶
type Store interface {
// Load returns ok=false when no record exists yet.
Load(name string) (rec Record, ok bool, err error)
Save(name string, rec Record) error
}
Store persists per-name quota records. Implementations must be concurrency-safe.
func NewFileStore ¶
func NewRedisStore ¶
func NewRedisStore(cfg RedisConfig) Store
Directories
¶
| Path | Synopsis |
|---|---|
|
Package wrapper adapts a named quota onto a listener and its connections, resolving the quota.Limiter by name from the registry on every call so create/update/delete takes effect live and several services can share one.
|
Package wrapper adapts a named quota onto a listener and its connections, resolving the quota.Limiter by name from the registry on every call so create/update/delete takes effect live and several services can share one. |