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")
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 ¶
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 ¶
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(...)