Documentation
¶
Overview ¶
Package mid provides standard net/http middleware for servicekit services: panic recovery, trace-context injection, access logging, request timeouts, and body size limits. All middleware have the signature func(http.Handler) http.Handler so they compose with router.Use and routegroup.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
Middleware is standard net/http middleware.
func AccessLog ¶
func AccessLog(log *logger.Logger) Middleware
AccessLog logs one structured line per request. Because it logs through the servicekit logger, each line carries the request's trace_id automatically.
func Panics ¶
func Panics(log *logger.Logger) Middleware
Panics recovers panics, logs the stack, and responds with 500.
func SizeLimit ¶
func SizeLimit(n int64) Middleware
SizeLimit caps the request body at n bytes. A non-positive n disables it.
func Timeout ¶
func Timeout(d time.Duration) Middleware
Timeout cancels the request context after d and (if nothing was written) lets downstream handlers observe ctx.Err. A non-positive d disables the middleware.
func TraceRequest ¶
func TraceRequest(tracer trace.Tracer) Middleware
TraceRequest seeds the request context with trace context extracted from incoming headers and ensures a trace id is available for logging.