correlation

package
v0.0.0-...-4f5bba3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

README

Correlation ID Middleware

The correlation ID middleware adds a X-Correlation-ID header to incoming requests, if they do not contain one already. The correlation ID can be used track the control flow in systems of microservices.

Example

finalHandler := midgard.StackMiddlewareHandler(
    []midgard.Middleware{
        correlation.New(),
    },
    http.HandlerFunc(HelloHandler),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...func(*Handler) error) (defs.Middleware, error)

New generates a new correlation id enriching middleware.

func WithLogLevel

func WithLogLevel(level slog.Level) func(h *Handler) error

WithLogLevel configures the log level to use with the logger.

func WithLogger

func WithLogger(log *slog.Logger) func(h *Handler) error

WithLogger configures the logger to use.

Types

type Handler

type Handler struct {
	defs.MWBase
}

func (*Handler) GetMWBase

func (h *Handler) GetMWBase() *defs.MWBase

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is implements the correlation id enriching middleware. It adds an X-Correlation-ID header if none was present.

Jump to

Keyboard shortcuts

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