golazy.dev golazy.dev / lazylimit Index | Files

package lazylimit

import "golazy.dev/lazylimit"

Package lazylimit provides generic rate limiting primitives.

Limiters are keyed by caller-provided strings, so the same package can back HTTP middleware, OAuth endpoints, MCP tools, or application services. The in-memory limiter is intended as a development and single-process backend; applications can provide another Store-compatible limiter for distributed deployments.

Functions

func Middleware

Middleware installs limiter in a standard HTTP stack.

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

Types

type Limiter

Limiter checks whether key can consume one unit.

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

type Result

Result describes one rate-limit check.

type Result struct {
	Allowed		bool
	Remaining	int
	ResetAfter	time.Duration
}