apistockdocs
v0.4 GitHub apistock.dev
Technical/Core packages

requestid

import "apistock.dev/requestid"Source on GitHub

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#

go
const Header = "X-Request-ID"

Header is the HTTP header carrying the request ID.

const MaxLength#

go
const MaxLength = 128

MaxLength is the longest accepted incoming request ID.

Functions#

func From#

go
func From(ctx context.Context) string

From returns the request ID in ctx, or "".

func New#

go
func New() string

New returns a random request ID such as "req_9f86d081884c7d65".

func Valid#

go
func Valid(id string) bool

Valid 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.Context

With returns a copy of ctx carrying id.

v0.4
esc
↑↓ move↵ openesc close