How can I send metadata from grpc-gateway to grpc server?
On the client(grpc-gateway):
func (c *Client) MiddlewareAuth(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
...
ctxOut := metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{
"key": "value",
}))
r = r.WithContext(ctxOut)
h.ServeHTTP(w, r)
})
}
On the server:
func (s *Server) List(ctx context.Context, request *pb.Request) (*pb.Response, error) {
md, _ := metadata.FromIncomingContext(ctx)
fmt.Println(md)
return &pb.Response{
Ok: true
}, nil
}