server

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 51 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OptionalJSONBody

func OptionalJSONBody(next http.Handler) http.Handler

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

func RequestIDHeader(next http.Handler) http.Handler

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

func StructuredLogger(logger *slog.Logger) func(http.Handler) http.Handler

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 RateLimiterConfig struct {
	RequestsPerSecond int
	Burst             int
}

type Server

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

func New

func New(ctx context.Context, core *app.Core) (*Server, error)

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

func (s *Server) Run(ctx context.Context) error

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.

Jump to

Keyboard shortcuts

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