hprose / hprose-go

Hprose 1.0 for Golang (Deprecated). Hprose 2.0 for Golang is here:
https://github.com/hprose/hprose-golang
MIT License
137 stars 13 forks source link

如何在service function中获取 gin.Context 对象? #2

Open donglei opened 6 years ago

donglei commented 6 years ago

项目中使用hprose 是就要gin框架 http server的,一些请求信息是放在header中,如何在 service function 中获取 gin.Context 对象,从而可以拿到Header 中的信息?

andot commented 6 years ago

将你服务方法的最后一个参数定义为:*http.Request 类型,hprose 服务器会自动传入这个对象,这个对象在 http 服务器下都是通用的(fasthttp 服务器除外),客户端调用时不需要传入这个参数。通过这个对象,你就可以拿到 Header 了。不需要直接存取 gin.Context。