middleware

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAddTraceIDHeaderMiddleware added in v0.2.0

func NewAddTraceIDHeaderMiddleware() mux.MiddlewareFunc

NewAddTraceIDHeaderMiddleware sets the `X-Trace-ID` response header to the trace ID of the request. It must run inside `NewTracingLoggingMiddleware`, which is what puts the trace ID in the request context; requests without a trace ID get no header.

func NewCORSMiddleware

func NewCORSMiddleware(allowedOrigins string) mux.MiddlewareFunc

func NewLogRequestMiddleware

func NewLogRequestMiddleware(logger *zap.Logger) mux.MiddlewareFunc

NewLogRequestMiddleware logs important debugging information about the incoming request like its `method`, the `host`, the `url` and the `headers`.

func NewTracingLoggingMiddleware

func NewTracingLoggingMiddleware(logger *zap.Logger) mux.MiddlewareFunc

NewTracingLoggingMiddleware adds a request specific logger containing the `trace_id` of the request extracted from the request propagation mechanism HTTP handlers can then easily extract a request specific logger using:

`logging.Logger(request.Context(), zlog)`

Types

type RandomTraceGetter

type RandomTraceGetter struct{}

RandomTrace is a fallback to insert a random trace ID if none was acquired from previous header lookups

func (RandomTraceGetter) Extract

Extract gives you a context with random TraceID and SpanID inserted if it didn't exist yet

func (RandomTraceGetter) Fields

func (p RandomTraceGetter) Fields() []string

Fields returns an empty list in RandomTraceGetter

func (RandomTraceGetter) Inject

Inject does not inject anything in RandomTraceGetter

Jump to

Keyboard shortcuts

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