Technical/Core packages
requestid
Package requestid generates, validates and carries request IDs in a context.Context, so HTTP middleware, logging, audit and jobs share one correlation value (ADR-0030).
Stability: pre-1.0 (ADR-0015).
Constants#
const Header#
go
const Header = "X-Request-ID"Header is the HTTP header carrying the request ID.
const MaxLength#
go
const MaxLength = 128MaxLength is the longest accepted incoming request ID.
Functions#
func From#
go
func From(ctx context.Context) stringFrom returns the request ID in ctx, or "".
func New#
go
func New() stringNew returns a random request ID such as "req_9f86d081884c7d65".
func Valid#
go
func Valid(id string) boolValid reports whether id is safe to accept from a client: 1 to MaxLength characters of letters, digits, '-', '_', '.' or ':'. This keeps untrusted IDs from injecting content into logs.
func With#
go
func With(ctx context.Context, id string) context.ContextWith returns a copy of ctx carrying id.
Was this page useful?
Open an issue
v0.4