Documentation
¶
Index ¶
- func OptionalJSONBody(next http.Handler) http.Handler
- func RateLimitRefreshMiddleware(rl *RateLimiter, onRefreshLimited func()) func(http.Handler) http.Handler
- func RequestIDHeader(next http.Handler) http.Handler
- func StructuredLogger(logger *slog.Logger) func(http.Handler) http.Handler
- type AuthRouteLimit
- type AuthRouteLimiter
- type RateLimiter
- type RateLimiterConfig
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OptionalJSONBody ¶
OptionalJSONBody gives a POST to those operations an empty JSON object when the client sent no body, as the spec allows.
func RateLimitRefreshMiddleware ¶
func RateLimitRefreshMiddleware(rl *RateLimiter, onRefreshLimited func()) func(http.Handler) http.Handler
onRefreshLimited, when set, observes refresh attempts the limiter refused.
func RequestIDHeader ¶
RequestIDHeader copies the chi request id into the X-Request-ID response header so callers can correlate a response with the server log line.
func StructuredLogger ¶
StructuredLogger emits one JSON log line per request with the fields operators filter on. It is deliberately conservative: it never logs request bodies, headers, query parameters, or credentials, so secrets cannot reach logs here.
Types ¶
type AuthRouteLimit ¶
type AuthRouteLimit struct {
// Path is the exact request path the bucket applies to.
Path string
// Kind is the bounded auth kind reported to metrics when a request is
// refused.
Kind string
// Every is the window Burst tokens are refilled over.
Every time.Duration
// Burst is the bucket capacity.
Burst int
}
AuthRouteLimit is one strict, per-IP token bucket on an auth route (#51): Burst requests per Every. With the shared limiter enabled the bucket lives in Redis and holds across the fleet; without it the limit is per replica.
type AuthRouteLimiter ¶
type AuthRouteLimiter struct {
// contains filtered or unexported fields
}
AuthRouteLimiter enforces one token bucket per route and client IP. The paths are exact matches, so a route not listed here is unaffected.
func NewAuthRouteLimiter ¶
func NewAuthRouteLimiter(limits []AuthRouteLimit, onLimited func(kind string), shared *realtime.Client) *AuthRouteLimiter
NewAuthRouteLimiter builds the strict auth-route limiter. onLimited, when set, observes the kind of every refused request.
func (*AuthRouteLimiter) Middleware ¶
func (l *AuthRouteLimiter) Middleware(next http.Handler) http.Handler
Middleware refuses a request with 429 and Retry-After once its route's bucket is exhausted.
func (*AuthRouteLimiter) Stop ¶
func (l *AuthRouteLimiter) Stop()
Stop halts the stale-entry cleanup goroutine.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
func NewRateLimiter ¶
func NewRateLimiter(cfg RateLimiterConfig, shared *realtime.Client) *RateLimiter
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(ctx context.Context, ip string) bool
Allow spends one request for ip. With the shared layer enabled the bucket lives in Redis, so the limit holds across replicas; a Redis error falls back to the local bucket (still better than no limit).
func (*RateLimiter) Cleanup ¶
func (rl *RateLimiter) Cleanup(age time.Duration)
func (*RateLimiter) IPCount ¶
func (rl *RateLimiter) IPCount() int
func (*RateLimiter) Stop ¶
func (rl *RateLimiter) Stop()
type RateLimiterConfig ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func New ¶
New builds the API on the shared graph (internal/app). ctx is the process context: background work started here (the assistant's in-process MCP session and sweeper) ends with it.
func (*Server) Run ¶
Run serves until ctx ends, then drains in-flight requests, and then the handlers' background work, for at most HTTPShutdownTimeout, or without a deadline when it is zero (#372). A clean shutdown returns nil; background work cut at the deadline is logged, not an exit failure. The rate limiters stop when Run returns.