在grpc中,在实现服务时,服务接口定义的方法只包含Context和Request。从Context的来源来看,它非常简单
type Context interface {
Deadline() (deadline time.Time, ok bool)
Done() <-chan struct{}
Err() error
Value(key interface{}) interface{}
}因此,我想知道是否有可能获得一些元数据(包括远程IP地址和其他数据)来维护会话。
谢谢。
发布于 2019-05-12 06:33:57
可以通过使用stats.Handler检索远程IP地址(特别是这个结构https://github.com/grpc/grpc-go/blob/v1.20.x/stats/stats.go#L89)。
grpc.Metadata通常用于存储有关会话的任意信息。
https://stackoverflow.com/questions/33684570
复制相似问题