Documentation
¶
Overview ¶
Package metadata provides request-scoped values for your RPC calls. You can use the standard context.Context package to store values for the request, true, but those will not follow you when you make an RPC call to another service. Metadata values *do* follow you as you hop from service to service, so they're ideal for trace data, identity data, etc.
The API for interacting with metadata values is similar to dealing w/ context values with the small modification that when you fetch a value, it accepts an 'out' parameter (like json.Unmarshal) instead of returning an interface{} value. This is a necessary evil due to limitations with Go's type system and reflection, but should only result in one extra line of code when fetching values from the metadata/context.
Index ¶
Constants ¶
const RequestHeader = "X-RPC-Values"
RequestHeader is the custom HTTP header that we use to encode your metadata values as you make RPC calls from service A to service B. Service B will decode this header to restore all of the metadata that you had while code was still running in service A.
Variables ¶
This section is empty.
Functions ¶
func ToJSON ¶
ToJSON serializes all of the metadata values into a single JSON string. You won't usually call this yourself as this is mainly used to set the X-RPC-Values header when making RPC calls to preserve your data across RPC calls.
func Value ¶
Value looks up a single piece of metadata on the specified context. The 'key' is the name of the value you're looking for and 'out' is a pointer to the value you want us to fill in - the mechanics are similar to json.Unmarshal().
func WithValue ¶
WithValue stores a key/value pair in the context metadata. It returns a new context that contains the metadata map with your value.
func WithValues ¶
WithValues does a wholesale replacement of ALL metadata values stored on the context. Usually you will not call this yourself - you should interact with individual values via Value()/WithValue(). This is typically just used by frodo internals to preserve your metadata across RPC calls.
Types ¶
type Values ¶
type Values map[string]valuesEntry
Values provides a lookup for all of the request-scoped data that you want to follow you as you make RPC calls from service to service (or client to service).
func FromJSON ¶
FromJSON rebuilds a Values map from the JSON embedded in an X-RPC-Values header. While it does make the Values map, all of the individual value entries will still be in their json formats rather than their unmarshaled raw Go values until they're explicitly used. See docs for Values for more info.