In grpc-go, when implementing a service, the service interface defines methods contains only Context
and Request
. From the source of the Context
, it is as simple as
type Context interface {
Deadline() (deadline time.Time, ok bool)
Done() <-chan struct{}
Err() error
Value(key interface{}) interface{}
}
So I wonder if it is possible to get some metadata (including remote IP address and other data) to maintain a session.
Thanks.
There's nothing that gRPC provides (in any language) that would be particularly robust as a session system across requests.
The streaming mechanism is great when you need to maintain context on a single server for clients: the stream callback's stack can point to whatever session information you need.
If you need state across separate RPC's (or across machines) you'll need to add your own session layer. You could do this by creating some unique id that you attach to (say) a 'my-session-id' metadata element when sending requests.