Reputation: 127
I'm using grpc.Dial(server)
in golang to setup a grpc connection to my server.
How do I send meta-data or custom headers through this Dial connection (from client side)?
Upvotes: 2
Views: 7815
Reputation: 6079
I presume grpc is your client connection object.
You create meta data using the metadata subpackage from a map[string]string (some other methods provided), you then pass it via context e.g
md := metadata.New(map[string]string{"key1": "val1", "key2": "val2"})
ctx := metadata.NewOutgoingContext(context.Background(), md)
Because you pass meta data via context you will need to use client.DialContext() rather than Dial I think https://godoc.org/google.golang.org/grpc#DialContext
See here for some examples - https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md
Upvotes: 10