middleware

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestLogger

func RequestLogger(logger *slog.Logger, logLevel slog.Level, formatter RequestLogFormatter) func(http.Handler) http.Handler

RequestLogger logs incoming HTTP requests.

func WithInflightMetrics

func WithInflightMetrics(m *metrics.InflightMetrics) func(next http.Handler) http.Handler

func WithRequestMetrics

func WithRequestMetrics(m metrics.RequestMetrics) func(next http.Handler) http.Handler

Types

type RequestLogFormatter

type RequestLogFormatter interface {
	FormatRequest(*http.Request, int, time.Duration) []slog.Attr
}

A RequestLogFormatter takes the HTTP request, the resulting HTTP status code and latency and formats the log entry.

var DefaultRequestLogFormatter RequestLogFormatter = &defaultRequestLogFormatter{}

DefaultRequestLogFormatter is the default RequestLogFormatter. It logs the request's HTTP method and the path, the response's status code and the latency of the request.

type RequestLogFormatterFunc

type RequestLogFormatterFunc func(r *http.Request, statusCode int, latency time.Duration) []slog.Attr

The RequestLogFormatterFunc type is an adapter that allows an ordinary function to be used as a RequestLogFormatter.

func (RequestLogFormatterFunc) FormatRequest

func (f RequestLogFormatterFunc) FormatRequest(r *http.Request, statusCode int, latency time.Duration) []slog.Attr

FormatRequest calls f(r, statusCode, latency)

Jump to

Keyboard shortcuts

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