ratelimit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ratelimit provides per-user in-memory rate limiting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

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

RateLimiter provides per-user in-memory rate limiting. Buckets reset every minute.

func NewRateLimiter

func NewRateLimiter(readLimit, writeLimit int) *RateLimiter

NewRateLimiter creates a rate limiter with per-minute limits.

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(userID string, isWrite bool) bool

Allow checks whether the user is within rate limits. isWrite should be true for mutating operations.

func (*RateLimiter) Middleware

func (rl *RateLimiter) Middleware(next http.Handler) http.Handler

Middleware returns an HTTP middleware that rate-limits based on the authenticated user's ID (from auth.TokenInfoFromContext). All MCP tool calls go through POST, so we use a simple heuristic: everything is counted as a "read" at the HTTP level. The per-tool read/write distinction could be added later via MCP middleware.

func (*RateLimiter) Stop

func (rl *RateLimiter) Stop()

Stop releases the rate limiter's background goroutine and ticker.

Jump to

Keyboard shortcuts

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