middleware

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package middleware provides production-ready HTTP middleware for serverless Lambda functions and local HTTP servers. All log output is structured JSON so entries are queryable with log aggregators (e.g. CloudWatch Logs Insights) without parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

LoggingMiddleware logs structured JSON entries for every request and response. Request entries include method, path, source IP, user agent, and request ID. Response entries add HTTP status, latency (ms), and an extracted error message for 4xx/5xx responses. Log level follows HTTP status: info/warn/error.

Compatible with any net/http handler, including chi routers.

func RecoverMiddleware

func RecoverMiddleware(next http.Handler) http.Handler

RecoverMiddleware catches panics in downstream handlers, logs a structured entry with the full stack trace, and writes a 500 Internal Server Error response. Without this middleware a panic crashes the Lambda invocation and returns an opaque 502 from API Gateway.

func RequestIDFromContext deprecated

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext extracts the request ID from the context. Returns an empty string if no request ID is present.

Deprecated: use ctxutil.RequestIDFrom. Retained for backward compatibility; it now reads the same ctxutil key.

Types

This section is empty.

Jump to

Keyboard shortcuts

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