go - How to access request headers in grpc service proxied by. grpc-gateway in golang
问题描述
I have a grpc server proxied by grpc-gateway. When I make a HTTP call to the gateway endpoint, my corresponding grpc service method is called. Now, the grpc service implementation receives a Context which has the headers. I couldn't figure out how to access the headers.
When I debug my grpc service and put a breakpoint, this is the structure of the Context object which my service receives. Now, how can I get the value of any of the HTTP request headers?
解决方案
HTTP 标头存储在元数据中。
md, ok := metadata.FromIncomingContext(ctx)
应该用于获取传入的元数据。
推荐阅读
- android - PagingLibrary 未加载更多数据
- php - 盖伊。HTTPS 重定向
- ssl-certificate - NativeScript 'tns run android' 抛出无法找到请求目标的有效认证路径
- intellij-idea - 集成终端在idea 2018中消失了
- stored-procedures - SQL Server 2017 存储过程需要声明表变量,但它已经存在
- php - 502 网关故障(1-C Bitrix)
- python - 如何计算列表中的重复列表?Python
- swift - iOS非阻塞状态栏
- java - 使用 Process 从 Java 代码执行 Java 程序
- javascript - 在记忆游戏中点击卡片不会翻转它