ratelimit

package
v0.10.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonBurst = "burst"
	ReasonQuota = "quota"
)

Variables

View Source
var ErrUnavailable = errors.New("rate limit entitlements unavailable")

ErrUnavailable means the gateway has no usable tier (HTTP 503 / JSON-RPC -32005).

Functions

func RetryAfterSeconds

func RetryAfterSeconds(d time.Duration) int

RetryAfterSeconds rounds a retry duration up to whole seconds.

Types

type Checker

type Checker interface {
	Check(ctx context.Context, gatewayID ids.GatewayID) error
}

func NewChecker

func NewChecker(tiers GatewayTierLoader, counter Counter, logger *slog.Logger) Checker

NewChecker builds the plan rate limiter (fail-open on Redis errors).

func NewNoopChecker

func NewNoopChecker() Checker

type Counter

type Counter interface {
	IncrBurst(ctx context.Context, gatewayID ids.GatewayID) (count int64, ttl time.Duration, err error)
	IncrQuota(ctx context.Context, gatewayID ids.GatewayID, month string) (count int64, err error)
}

type Exceeded

type Exceeded struct {
	Reason     string
	Limit      int
	Remaining  int
	RetryAfter time.Duration
}

Exceeded is returned when a plan limit is hit (HTTP 429 / JSON-RPC -32004).

func (*Exceeded) Body

func (e *Exceeded) Body() []byte

func (*Exceeded) Error

func (e *Exceeded) Error() string

func (*Exceeded) Headers

func (e *Exceeded) Headers() map[string][]string

type GatewayTierLoader

type GatewayTierLoader interface {
	Tier(ctx context.Context, gatewayID ids.GatewayID) (string, error)
}

func NewGatewayTierLoader

func NewGatewayTierLoader(finder appgateway.Finder) GatewayTierLoader

NewGatewayTierLoader prefers the gateway on ctx over Finder.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL