Documentation
¶
Overview ¶
Package metadata is a way of defining message headers
Index ¶
- Variables
- func AppendContext(ctx context.Context, kv ...string) context.Context
- func AppendIncomingContext(ctx context.Context, kv ...string) context.Context
- func AppendOutgoingContext(ctx context.Context, kv ...string) context.Context
- func NewContext(ctx context.Context, md Metadata) context.Context
- func NewIncomingContext(ctx context.Context, md Metadata) context.Context
- func NewOutgoingContext(ctx context.Context, md Metadata) context.Context
- func ValueFromCurrentContext(ctx context.Context, key string) []string
- func ValueFromIncomingContext(ctx context.Context, key string) []string
- func ValueFromOutgoingContext(ctx context.Context, key string) []string
- type Iterator
- type Metadata
- func Copy(src Metadata) Metadata
- func FromContext(ctx context.Context) (Metadata, bool)
- func FromIncomingContext(ctx context.Context) (Metadata, bool)
- func FromOutgoingContext(ctx context.Context) (Metadata, bool)
- func Join(mds ...Metadata) Metadata
- func MustContext(ctx context.Context) Metadata
- func MustIncomingContext(ctx context.Context) Metadata
- func MustOutgoingContext(ctx context.Context) Metadata
- func New(l int) Metadata
- func NewWithMetadata(m map[string]string) Metadata
- func Pairs(kv ...string) Metadata
- func (md Metadata) Add(key string, vals ...string)
- func (md Metadata) Append(key string, vals ...string)
- func (md Metadata) AsHTTP1() map[string][]string
- func (md Metadata) AsHTTP2() map[string][]string
- func (md Metadata) Copy() Metadata
- func (md Metadata) CopyTo(out Metadata)
- func (md Metadata) Del(k ...string)
- func (md Metadata) Get(k string) ([]string, bool)
- func (md Metadata) GetJoined(k string) (string, bool)
- func (md Metadata) Iterator() *Iterator
- func (md Metadata) Len() int
- func (md Metadata) MustGet(k string) []string
- func (md Metadata) MustGetJoined(k string) string
- func (md Metadata) Set(kvs ...string)
Constants ¶
This section is empty.
Variables ¶
var ( // HeaderTopic is the header name that contains topic name HeaderTopic = "Micro-Topic" // HeaderContentType specifies content type of message HeaderContentType = "Content-Type" // HeaderEndpoint specifies endpoint in service HeaderEndpoint = "Micro-Endpoint" // HeaderService specifies service HeaderService = "Micro-Service" // HeaderTimeout specifies timeout of operation HeaderTimeout = "Micro-Timeout" // HeaderAuthorization specifies Authorization header HeaderAuthorization = "Authorization" // HeaderXRequestID specifies request id HeaderXRequestID = "X-Request-Id" )
Functions ¶
func AppendContext ¶ added in v4.1.0
AppendContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.
func AppendIncomingContext ¶
AppendIncomingContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.
func AppendOutgoingContext ¶
AppendOutgoingContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.
func NewContext ¶
NewContext creates a new context with Metadata attached. Metadata must not be modified after calling this function.
func NewIncomingContext ¶
NewIncomingContext creates a new context with incoming Metadata attached. Metadata must not be modified after calling this function.
func NewOutgoingContext ¶
NewOutgoingContext creates a new context with outgoing Metadata attached. If used in conjunction with AppendOutgoingContext, NewOutgoingContext will overwrite any previously-appended metadata. Metadata must not be modified after calling this function.
func ValueFromCurrentContext ¶ added in v4.1.0
ValueFromCurrentContext returns the metadata value corresponding to the metadata key from the incoming metadata if it exists. Keys are matched in a case insensitive manner.
func ValueFromIncomingContext ¶ added in v4.1.0
ValueFromIncomingContext returns the metadata value corresponding to the metadata key from the incoming metadata if it exists. Keys are matched in a case insensitive manner.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator used to iterate over metadata with order
type Metadata ¶
Metadata is a mapping from metadata keys to values. Users should use the following two convenience functions New and Pairs to generate Metadata.
func FromContext ¶
FromContext returns the metadata in ctx if it exists.
func FromIncomingContext ¶
FromIncomingContext returns the incoming metadata in ctx if it exists.
func FromOutgoingContext ¶
FromOutgoingContext returns the outgoing metadata in ctx if it exists.
func Join ¶ added in v4.1.0
Join joins any number of Metadatas into a single Metadata.
The order of values for each key is determined by the order in which the Metadatas containing those values are presented to Join.
func MustContext ¶ added in v4.1.0
MustContext returns the metadata in ctx.
func MustIncomingContext ¶ added in v4.1.0
MustIncomingContext returns the incoming metadata in ctx.
func MustOutgoingContext ¶ added in v4.1.0
MustOutgoingContext returns the outgoing metadata in ctx.
func NewWithMetadata ¶ added in v4.1.0
NewWithMetadata creates an Metadata from a given key-value map.
func Pairs ¶
Pairs returns an Metadata formed by the mapping of key, value ... Pairs panics if len(kv) is odd.
func (Metadata) Append ¶ added in v4.0.18
Append adds the values to key k, not overwriting what was already stored at that key.
func (Metadata) AsHTTP1 ¶ added in v4.1.0
AsHTTP1 returns a copy of Metadata with CanonicalMIMEHeaderKey.
func (Metadata) GetJoined ¶ added in v4.1.0
GetJoined obtains the values for a given key with joined values with "," symbol
func (Metadata) MustGetJoined ¶ added in v4.1.0
MustGetJoined obtains the values for a given key with joined values with "," symbol