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.