middleware

package
v0.0.0-...-88e46a0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogger

func GetLogger(ctx context.Context) *zap.Logger

GetLogger returns a request logger from the given context if one is present.

func IsStatusRequest

func IsStatusRequest(r *http.Request) bool

IsStatusRequest checks if the request is a health check request

func Recovery

func Recovery(next http.Handler) http.Handler

Recovery is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible. Recoverer prints a request ID if one is provided.

Alternatively, look at https://github.com/pressly/lg middleware pkgs.

func SetID

func SetID(ctx context.Context, requestID string) context.Context

SetID sets ID

func SetLogger

func SetLogger(ctx context.Context, logger *zap.Logger) context.Context

SetLogger sets logger

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a middleware that injects logger with request ID into the context of each request.

func NewLogger

func NewLogger(logger *zap.Logger) *Logger

NewLogger creates new Logger instance

func (*Logger) Handler

func (l *Logger) Handler(next http.Handler) http.Handler

Handler is the request handler that creates logger instance for each request with corresponding request ID.

type RequestLogger

type RequestLogger struct{}

RequestLogger is a struct for logging request

func NewRequestLogger

func NewRequestLogger() *RequestLogger

NewRequestLogger creates new request logger

func (*RequestLogger) Handler

func (m *RequestLogger) Handler(next http.Handler) http.Handler

Handler handles request logging

Jump to

Keyboard shortcuts

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