ratelimit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package ratelimit implements concurrency-safe in-memory token buckets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(l Limiter, key func(*http.Request) string) func(http.Handler) http.Handler

Middleware returns context-aware HTTP admission or coordination middleware.

Types

type Config

type Config struct {
	Rate           float64
	Burst, MaxKeys int
	IdleTTL        time.Duration
	Now            func() time.Time
}

Config contains explicit constructor settings; see package documentation for defaults.

type Decision

type Decision struct {
	Allowed    bool
	Remaining  int
	RetryAfter time.Duration
	Limit      int
}

Decision contains admission and retry-after metadata.

type Limiter

type Limiter interface {
	Allow(context.Context, string) (Decision, error)
}

Limiter evaluates a context-aware rate policy.

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

Memory provides bounded process-local coordination.

func New

func New(c Config) (*Memory, error)

New constructs and validates an explicitly owned instance. See package documentation for defaults and cleanup.

func (*Memory) Allow

func (m *Memory) Allow(ctx context.Context, key string) (Decision, error)

Allow evaluates the configured rate policy for a key.

Jump to

Keyboard shortcuts

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