Documentation
¶
Overview ¶
Package metadata provides a request-scoped key-value map that propagates through RPC and REST call chains. It is the gofly equivalent of gRPC metadata, stored in context.Context and safe for concurrent read-only use.
Package metadata provides a request-scoped key-value map that propagates through RPC and REST call chains.
Index ¶
- Constants
- func Append(ctx context.Context, kv ...string) context.Context
- func EnsureRequestID(ctx context.Context) (context.Context, string)
- func NewContext(ctx context.Context, md MD) context.Context
- func NewRequestID() string
- func RequestIDFromContext(ctx context.Context) string
- func WithRequestID(ctx context.Context, id string) context.Context
- type MD
Constants ¶
const RequestIDKey = "request_id"
RequestIDKey is the metadata key for request identifiers.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append adds key/value pairs to the MD stored in ctx, creating a new MD if none exists. Keys are overwritten on duplicate.
func EnsureRequestID ¶
EnsureRequestID returns ctx unchanged when it already carries a request id, or a derived context with a freshly generated id otherwise. The second return value is the resolved id.
func NewContext ¶
NewContext returns a new context carrying md. The stored value is a clone of the supplied map.
func NewRequestID ¶
func NewRequestID() string
NewRequestID returns a 32-hex-character random identifier. Falls back to a base-36 timestamp if the system RNG fails.
func RequestIDFromContext ¶
RequestIDFromContext extracts the request_id stored in the context metadata. Returns an empty string when absent.
Types ¶
type MD ¶
MD is a string-to-string metadata map.
func FromContext ¶
FromContext extracts MD from ctx. The returned MD is a clone and safe to mutate without affecting the stored value.