metadata

package
v0.0.0-...-c124da1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
const RequestIDKey = "request_id"

RequestIDKey is the metadata key for request identifiers.

Variables

This section is empty.

Functions

func Append

func Append(ctx context.Context, kv ...string) context.Context

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

func EnsureRequestID(ctx context.Context) (context.Context, string)

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

func NewContext(ctx context.Context, md MD) context.Context

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

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext extracts the request_id stored in the context metadata. Returns an empty string when absent.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID returns a derived context carrying the given request id in its metadata. If id is empty a fresh id is generated.

Types

type MD

type MD map[string]string

MD is a string-to-string metadata map.

func FromContext

func FromContext(ctx context.Context) (MD, bool)

FromContext extracts MD from ctx. The returned MD is a clone and safe to mutate without affecting the stored value.

func New

func New(kv ...string) MD

New creates an MD from alternating key/value strings.

func (MD) Clone

func (md MD) Clone() MD

Clone returns a shallow copy of md.

func (MD) Get

func (md MD) Get(key string) string

Get returns the value for key or "" if md is nil or the key is absent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL