middleware

package
v0.0.0-...-d5bad45 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

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