middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(l *slog.Logger, extensions ...LogExtension) func(http.Handler) http.Handler

Logger middleware injects logger into each request context Logger is configured slog.Logger with additions of LogExtension.

func LoggerFrom

func LoggerFrom(ctx context.Context) *slog.Logger

LoggerFrom gets a logger from the context.

func MethodLog

func MethodLog(r *http.Request) (slog.Attr, bool)

MethodLog logger extension for log request method.

func RequestID

func RequestID(next http.Handler) http.Handler

RequestID middleware injects request id for each request. It searches for X-Request-ID header in request, if not present, generates a new one.

func RequestIDFrom

func RequestIDFrom(ctx context.Context) string

RequestIDFrom extracts request id from context. Returns empty string if request id can not be found.

func RequestIDLog

func RequestIDLog(r *http.Request) (slog.Attr, bool)

RequestIDLog logger extension for log request id.

func WithLogger

func WithLogger(ctx context.Context, logger *slog.Logger) context.Context

WithLogger injects logger in the context.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID injects request id into the context. Generates new UUID if id is empty string. Generates new UUID if id isn't a correct UUID.

Types

type LogExtension

type LogExtension func(r *http.Request) (slog.Attr, bool)

LogExtension is an additional attributes for logging.

Jump to

Keyboard shortcuts

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