Documentation
¶
Overview ¶
Package requestcontext provides middleware that attaches a small request-scoped context to each request: a unique request ID and a start timestamp. The ID is also echoed in the X-Request-Id response header, easing log correlation across services.
Index ¶
Constants ¶
View Source
const HeaderName = "X-Request-Id"
HeaderName is the response header used to expose the request ID.
View Source
const Key = "ctx"
Key is the request value key under which the *Ctx is stored.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Ctx ¶
type Ctx struct {
// ID uniquely identifies the request.
ID string
// Start is the time the request entered the middleware.
Start time.Time
}
Ctx is the per-request context attached by this middleware.
type Options ¶
type Options struct {
// TrustHeader, when true, reuses an incoming X-Request-Id header (if
// present and non-empty) instead of generating a new ID. This is useful
// behind a trusted proxy that assigns request IDs.
TrustHeader bool
// Generator overrides the default random ID generator.
Generator func() string
}
Options configures the requestcontext middleware.
Click to show internal directories.
Click to hide internal directories.