middleware

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 6 Imported by: 0

README

Ideas Explored and Rejected (EARs):

* Rev	Provide Queue/Stack as middleware arrangement functions

	Present in v0.2.0; removed in v0.3.0 on 2025-07-25	

	While these convenience functions for chaining
	middleware seem helpful, they obscure execution order 
	and introduce ambiguity in naming. For example, does
	Queue imply middleware is applied in first-in-first-out
	order, or executed that way - which is arrangement in
	precisely the reverse order? Such abstractions 
	sacrifice clarity for superficially cleaner code.


* Prop	Include 'common' header-setting middleware
	
	Rejected on 2025-07-25

	Middleware that sets common headers - e.g., CORS or 
	OWASP secure headers - can simplify security 
	configuration. However, when additional headers are set
	within handlers, reasoning about the final response
	requires checking multiple places. This breaks locality
	of behavior and reduces clarity, expecially in light of
	the Response representation in package messsages.

Documentation

Overview

Package middleware provides composable HTTP middleware for use with net/http. It includes utilities for panic recovery, access logging, and middleware chaining.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLogger

func AccessLogger(logger *slog.Logger, prefix string) func(h http.Handler) http.Handler

AccessLogger returns middleware that logs request and response details. If logger is nil, slog.Default() is used.

Fields logged include remote address, method, URL, protocol, response status, user agent, and request duration.

func RecoverAndHandle

func RecoverAndHandle(logger *slog.Logger, fallback http.Handler) func(h http.Handler) http.Handler

RecoverAndHandle returns middleware that recovers from panics in downstream handlers. If a panic occurs, it logs the error and stack trace using logger, then delegates to the fallback handler.

If logger is nil, slog.Default() is used.

Types

This section is empty.

Jump to

Keyboard shortcuts

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