metadata

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToClientContext

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

AppendToClientContext returns a new context with the provided kv merged with any existing metadata in the context. This functions is a modification of grpc.AppendToOutgoingContext

func MergeToClientContext

func MergeToClientContext(ctx context.Context, cmd Metadata) context.Context

MergeToClientContext merge new metadata into ctx.

func NewClientContext

func NewClientContext(ctx context.Context, md Metadata) context.Context

NewClientContext creates a new context with client md attached. This function is implemented in the same way as in NewServerContext and grpc.NewIncomingContext

func NewServerContext

func NewServerContext(ctx context.Context, md Metadata) context.Context

NewServerContext creates a new context with client md attached. This function is implemented in the same way as NewClientContext and grpc.NewIncomingContext

Types

type Metadata

type Metadata map[string][]string

Metadata is our way of representing request headers internally. They're used at the RPC level and translate back and forth from Transport headers.

func FromClientContext

func FromClientContext(ctx context.Context) (Metadata, bool)

FromClientContext returns the client metadata in ctx if it exists. 从context中获取client metadata

func FromServerContext

func FromServerContext(ctx context.Context) (Metadata, bool)

FromServerContext returns the server metadata in ctx if it exists. This function is a modification of grpc.fromOutgoingContextRaw

func New

func New(mds ...map[string][]string) Metadata

New creates an MD from a given key-values map. Different the metadata.New from grpc.metadata, this function will not convert the key to lowercase. This function allow to input multi map[string] with the velue is []string In the return Metadata, a key may appear corresponding to multiple values.

func (Metadata) Add

func (m Metadata) Add(key, value string)

Add adds the key, value pair to the header.

func (Metadata) DeepClone

func (md Metadata) DeepClone() Metadata

DeepClone returns a deep copy of Metadata

func (Metadata) Get

func (m Metadata) Get(key string) string

Get returns the value associated with the passed key.

func (Metadata) Range

func (m Metadata) Range(f func(k string, v []string) bool)

Range iterate over element in metadata.

func (Metadata) Set

func (m Metadata) Set(key string, value string)

Set stores the key-value pair.

func (Metadata) Values

func (m Metadata) Values(key string) []string

Values returns a slice of values associated with the passed key.

Jump to

Keyboard shortcuts

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