Documentation
¶
Overview ¶
Package ctxutil provides small, domain-agnostic helpers for threading values through context.Context. It currently carries an HTTP request id so a single id can be propagated across handler, service, and worker boundaries without callers threading it explicitly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestIDFrom ¶
RequestIDFrom returns the request id stamped on ctx, or "" when none is present. Services and workers use this to read the id without taking a dependency on the HTTP layer that originally set it.
func RequestIDFromMetadata ¶ added in v0.3.2
RequestIDFromMetadata extracts the request id from a JSON metadata blob, or returns "" when none is present. It tolerates an empty or malformed blob and returns "" rather than erroring, so a partial upgrade across an old stored row does not crash the consumer.
func RequestIDToMetadata ¶ added in v0.3.2
RequestIDToMetadata returns a JSON object blob (always non-empty) carrying the request id under the "request_id" key. base, when non-empty, is merged in first so a caller-supplied metadata blob can carry additional tags alongside the request id; an empty or malformed base is ignored. When requestID is empty the id is simply not stamped. The result is never empty: a marshal failure (or an empty result) falls back to "{}", so callers can persist the return value into a NOT NULL JSON column without branching.
It is the write side of the request-id-over-metadata seam: a producer copies the id from context into a row's metadata at enqueue time, and a consumer reads it back with RequestIDFromMetadata across the storage boundary.
Types ¶
This section is empty.