Documentation ¶
Overview ¶
Package metadata define the structure of the metadata supported by gRPC library. Please refer to https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md for more information about custom-metadata.
Index ¶
- Variables
- func AppendToOutgoingContext(ctx context.Context, kv ...string) context.Context
- func NewIncomingContext(ctx context.Context, md MD) context.Context
- func NewOutgoingContext(ctx context.Context, md MD) context.Context
- func SetCodec(c Codec)
- type Codec
- type MD
- func (md MD) Append(k string, vals ...string)
- func (md MD) Copy() MD
- func (md MD) Delete(k string)
- func (md MD) Get(k string) []string
- func (md MD) GetFirstInt(k string) (int64, bool)
- func (md MD) GetFirstString(k string) (string, bool)
- func (md MD) Len() int
- func (md MD) Set(k string, vals ...string)
- func (md MD) SetInt(k string, vals ...int64)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSize = errors.New("invalid size")
Functions ¶
func AppendToOutgoingContext ¶
AppendToOutgoingContext 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 NewIncomingContext ¶
NewIncomingContext creates a new context with incoming md attached.
func NewOutgoingContext ¶
NewOutgoingContext creates a new context with outgoing md attached. If used in conjunction with AppendToOutgoingContext, NewOutgoingContext will overwrite any previously-appended metadata.
Types ¶
type MD ¶
MD is a mapping from metadata keys to values. Users should use the following two convenience functions New and Pairs to generate MD. NOTE: copy from grpc and add some functions.
func FromIncomingContext ¶
FromIncomingContext returns the incoming metadata in ctx if it exists.
All keys in the returned MD are lowercase.
func FromOutgoingContext ¶
FromOutgoingContext returns the outgoing metadata in ctx if it exists.
All keys in the returned MD are lowercase.
func FromOutgoingContextRaw ¶
FromOutgoingContextRaw returns the un-merged, intermediary contents of rawMD.
Remember to perform strings.ToLower on the keys, for both the returned MD (MD is a map, there's no guarantee it's created using our helper functions) and the extra kv pairs (AppendToOutgoingContext doesn't turn them into lowercase).
This is intended for gRPC-internal use ONLY. Users should use FromOutgoingContext instead.
func Join ¶
Join joins any number of mds into a single MD.
The order of values for each key is determined by the order in which the mds containing those values are presented to Join.
func New ¶
New creates an MD from a given key-value map.
Only the following ASCII characters are allowed in keys:
- digits: 0-9
- uppercase letters: A-Z (normalized to lower)
- lowercase letters: a-z
- special characters: -_.
Uppercase letters are automatically converted to lowercase.
Keys beginning with "grpc-" are reserved for grpc-internal use only and may result in errors if set in metadata.
func Pairs ¶
Pairs returns an MD formed by the mapping of key, value ... Pairs panics if len(kv) is odd.
Only the following ASCII characters are allowed in keys:
- digits: 0-9
- uppercase letters: A-Z (normalized to lower)
- lowercase letters: a-z
- special characters: -_.
Uppercase letters are automatically converted to lowercase.
Keys beginning with "grpc-" are reserved for grpc-internal use only and may result in errors if set in metadata.
func (MD) Append ¶
Append adds the values to key k, not overwriting what was already stored at that key.
k is converted to lowercase before storing in md.
func (MD) Delete ¶
Delete removes the values for a given key k which is converted to lowercase before removing it from md.
func (MD) Get ¶
Get obtains the values for a given key.
k is converted to lowercase before searching in md.
func (MD) GetFirstInt ¶
GetFirstInt get the first value of given key convert to int type,and return wether the value exists.
func (MD) GetFirstString ¶
GetFirstString get the first value of given key,and return wether the value exists.