Documentation
¶
Overview ¶
Package ratelimitx defines Kernel's rate limit provider contract.
It separates policy semantics from middleware wiring. MEMORY is local to one process/pod and is safe for demos or per-instance self-protection. Cluster-wide quotas must use REDIS or EXTERNAL providers and are validated by bootx/serverx or clientpolicyx before the service starts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLimited = errorx.TooManyRequests("RATE_LIMIT_EXCEEDED", "request rejected by rate limit")
ErrLimited is the canonical cross-protocol error returned by rate-limit middleware.
Functions ¶
This section is empty.
Types ¶
type FailMode ¶
type FailMode string
FailMode controls behavior when a distributed provider is unavailable.
type KeyStrategy ¶
type KeyStrategy string
KeyStrategy names how middleware should derive a limiter key.
const ( KeyOperation KeyStrategy = "operation" KeyPrincipal KeyStrategy = "principal" KeyTenant KeyStrategy = "tenant" KeyCaller KeyStrategy = "caller" KeyCustom KeyStrategy = "custom" )
type Limiter ¶
Limiter is the runtime interface used by middleware.
func NewMemoryLimiter ¶
NewMemoryLimiter creates a local token bucket limiter.
type MemoryProvider ¶
type MemoryProvider struct{}
MemoryProvider implements per-process token buckets. It is intentionally local and must not be used for cluster-wide quotas.
func NewMemoryProvider ¶
func NewMemoryProvider() *MemoryProvider
func (*MemoryProvider) NewLimiter ¶
func (p *MemoryProvider) NewLimiter(policy Policy) (Limiter, error)
type Policy ¶
type Policy struct {
Name string
Enabled bool
Backend Backend
Scope Scope
Key KeyStrategy
QPS float64
Burst int
FailMode FailMode
}
Policy is the normalized rate-limit contract used by server and client autowire.
func (Policy) Normalize ¶
Normalize fills production-safe defaults without weakening the declared scope.
func (Policy) ValidateForDeployment ¶
ValidateForDeployment checks topology-sensitive constraints.