limit

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package limit is the ingress-protection middleware (ADR-0112, F75): it refuses abusive traffic on the data-plane chain BEFORE dataplane.Handler — and therefore before the activator can wake a scaled-to-zero sandbox (the reject returns without ever calling activator.ServeHTTP). Three composable net/http middlewares: a token-bucket rate limit (429), a Content-Length body-size cap (413), and an in-flight concurrency ceiling (503), all RFC 9457 problem+json. It is inserted as the innermost middleware (Recover → RequestID → limit → handler) so rejects stay panic-guarded and X-Request-Id-correlated while still preceding the activator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(cfg Config) func(http.Handler) http.Handler

Chain returns a single middleware composing rate → size → concurrency (cheapest reject first). A zero Config is a pass-through.

Types

type Config

type Config struct {
	RatePerMin   int   // token-bucket refill (requests per minute); 0 ⇒ rate limit off
	Burst        int   // bucket depth; 0 ⇒ = RatePerMin
	Key          Key   // clientIP (default) | function
	MaxBodyBytes int64 // 413 over this (Content-Length); 0 ⇒ size cap off
	MaxInFlight  int   // 503 over this many concurrent; 0 ⇒ concurrency cap off
	MaxKeys      int   // LRU cap on the rate-limiter key map; 0 ⇒ defaultMaxKeys
}

Config configures the three limiters. A zero Config is a pass-through.

type Key

type Key string

Key selects the rate-limit bucket dimension.

const (
	// KeyClientIP buckets per client IP (anti-abuse).
	KeyClientIP Key = "clientIP"
	// KeyFunction buckets per /function/<name> head (the first two path segments) — NOT the raw
	// path, so a rest-varying flood shares one bucket and cannot churn the key map.
	KeyFunction Key = "function"
)

Jump to

Keyboard shortcuts

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