Metadata

Example:metadata

Clients and servers can communicate with extra data.

Metadata is a key-vaue pair and key/value must be string.

Client

If you want to send metadata, you must set share.ReqMetaDataKey in context.If you want to receive metadata, you must set share.ResMetaDataKey in context.

```go client.go reply := &example.Reply{} ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{"aaa": "from client"}) ctx = context.WithValue(ctx, share.ResMetaDataKey, make(map[string]string)) err := xclient.Call(ctx, "Mul", args, reply)

  1. ## Server
  2. Server can get `share.ReqMetaDataKey` and `share.ResMetaDataKey` from context:
  3. ```go server.go
  4. reqMeta := ctx.Value(share.ReqMetaDataKey).(map[string]string)
  5. resMeta := ctx.Value(share.ResMetaDataKey).(map[string]string)

By smallnest updated 2018-03-27 11:12:10

原文:

http://doc.rpcx.site/part3/metadata.html