metadata

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetaClient

type MetaClient struct{}

func (*MetaClient) NewOutgoingMetadataContext

func (c *MetaClient) NewOutgoingMetadataContext(sourceCtx context.Context, kvPairs map[string]string) (context.Context, error)

NewOutgoingMetadataContext creates a new outgoing context with kv pairs, to be used during rpc call

Example:

mc := &MetaClient{}
ctx, err := mc.NewOutgoingMetadataContext(context.Background(), map[string]string{...})

<for unary rpc calls>
	var header, trailer metadata.MD
	r, err := x.UnaryRPCMethod(ctx, &pb.XyzRequest{...}, grpc.Header(&header), grpc.Trailer(&trailer))
	v := mc.Value(header, "xyz")
	v := mc.Value(trailer, "efg")
	v := mc.Slice(header, "yyy")

<for stream calls>
	stream, err := x.ServerStreamRPCMethod(ctx, &pb.XyzRequest{...})

	header, err := stream.Header()
	trailer, err := stream.Trailer()

	v := mc.Value(header, "xyz")
	v := mc.Value(header, "efg")
	v := mc.Slice("header", "yyy")

func (*MetaClient) Slice

func (c *MetaClient) Slice(md metadata.MD, key string) []string

Slice is a helper that retrieves string slice from metadata header or trailer

func (*MetaClient) Value

func (c *MetaClient) Value(md metadata.MD, key string) string

Value is a helper that retrieves string value from metadata header or trailer

type MetaServer

type MetaServer struct{}

func (*MetaServer) FromIncomingMetadataContext

func (s *MetaServer) FromIncomingMetadataContext(sourceCtx context.Context) (kv map[string][]string, err error)

FromIncomingMetadataContext retrieves kv pairs from incoming metadata context, and return as map this method is called from within server side RPC method handler

Example:

ms := &MetaServer{}
m, err := ms.FromIncomingMetadataContext(ctx)
v1 := m["xyz"]
v2 := m["efg"]

func (*MetaServer) SendHeader

func (s *MetaServer) SendHeader(ctx context.Context, kvPairs map[string]string) error

SendHeader will send metadata header by server, may be called at most only once per rpc call

within RPC call, just before RPC returns response, call SendHeader to send header metadata to caller

func (*MetaServer) SetTrailer

func (s *MetaServer) SetTrailer(ctx context.Context, kvPairs map[string]string) error

SetTrailer is called via 'defer', so that after RPC call response is given, the defer is triggered to set Trailer, if applicable such as: defer ms.SetTrailer(...)

Jump to

Keyboard shortcuts

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