metadata

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Unlicense Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToOutgoingContext

func AppendToOutgoingContext(ctx context.Context, k string, v ...string) context.Context

AppendToOutgoingContext returns a new context with the provided kv added to the existing outgoing metadata. This will overwrite any previously-appended metadata. This will modify the provided context.

func NewIncomingContext

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

NewIncomingContext creates a new context with incoming md attached.

func NewOutgoingContext

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

NewOutgoingContext creates a new context with outgoing md attached. If used in conjunction with AppendToOutgoingContext, NewOutgoingContext will overwrite any previously-appended metadata.

func ValueFromIncomingContext

func ValueFromIncomingContext(ctx context.Context, key string) string

ValueFromIncomingContext returns the metadata value corresponding to the metadata key from the incoming metadata if it exists.

Types

type MD

type MD map[string][]string

A MD represents the key-value pairs in an RPC Metadata.

The keys should be in canonical form, as returned by [CanonicalHeaderKey].

func FromIncomingContext

func FromIncomingContext(ctx context.Context) MD

FromIncomingContext returns the incoming metadata in ctx and will always be a non-nil map.

func FromOutgoingContext

func FromOutgoingContext(ctx context.Context) MD

FromIncomingContext returns the incoming metadata in ctx if it exists.

func Pairs

func Pairs(kv ...string) MD

Pairs returns an MD formed by the mapping of key, value ... Pairs panics if len(kv) is odd.

The key is case insensitive; it is canonicalized by [CanonicalHeaderKey].

Keys beginning with "grpc-" are reserved for grpc-internal use only and may result in errors if set in metadata.

func (MD) Add

func (md MD) Add(key, value string)

Add adds the key, value pair to the header. It appends to any existing values associated with key. The key is case insensitive; it is canonicalized by [CanonicalHeaderKey].

func (MD) Del

func (md MD) Del(key string)

Del deletes the values associated with key. The key is case insensitive; it is canonicalized by [CanonicalHeaderKey].

func (MD) Get

func (md MD) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "". It is case insensitive; textproto.CanonicalMIMEHeaderKey is used to canonicalize the provided key. Get assumes that all keys are stored in canonical form. To use non-canonical keys, access the map directly.

func (MD) Set

func (md MD) Set(key string, value ...string)

Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key. The key is case insensitive; it is canonicalized by textproto.CanonicalMIMEHeaderKey. To use non-canonical keys, assign to the map directly.

func (MD) Values

func (md MD) Values(key string) []string

Values returns all values associated with the given key. It is case insensitive; textproto.CanonicalMIMEHeaderKey is used to canonicalize the provided key. To use non-canonical keys, access the map directly. The returned slice is not a copy.

Jump to

Keyboard shortcuts

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