middleware

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 12 Imported by: ? 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

Overview

Package middleware provides the HTTP middlewares that log requests and record their errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLog added in v0.2.0

func AccessLog() func(ctx context.Context, logger *slog.Logger, r *accesslog.Record)

AccessLog writes the access log record of a request, the one LogRequest defines, from what the accesslog middleware of huma-middleware knows about it. It is the function given to accesslog.WithRecordFunc: the record is pooled, everything is copied during the call. The error of the request (RecordError) is not read from the record: the logger the function receives is the one of the request logger, which adds the attributes of the request (the error among them) to the line.

func LogRequest added in v0.2.0

func LogRequest(ctx context.Context, logger *slog.Logger, r *RequestRecord)

LogRequest logs a request at the level of its status: server errors are errors, client errors warnings, the rest is debug. Nothing is built when the level is disabled.

func RecordError added in v0.2.0

func RecordError(ctx context.Context, err error)

RecordError keeps err as the error of the request: the access log reports it.

func SkipHuma added in v0.2.0

func SkipHuma(debug bool) func(huma.Context) bool

SkipHuma is the skipper of the access log for a huma operation: the monitoring endpoints are not logged, unless the debug level is on and everything is logged.

func SkipRequest added in v0.2.0

func SkipRequest(debug bool) func(*http.Request) bool

SkipRequest is SkipHuma for a plain http.Handler.

Types

type RequestRecord added in v0.2.0

type RequestRecord struct {
	Err       error
	RemoteIP  string
	Host      string
	Method    string
	URI       string
	UserAgent string
	RequestID string
	Latency   time.Duration
	Size      int64
	Status    int
}

RequestRecord is what the request logger logs about a request. It holds no framework type, so the logging is the same whatever the router that fills it.

Jump to

Keyboard shortcuts

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