add peer in context
This commit is contained in:
parent
b4b76d452a
commit
d8e998ad85
@ -28,6 +28,7 @@ import (
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/encoding"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/peer"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
@ -203,6 +204,12 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
// create new context
|
||||
ctx := meta.NewContext(stream.Context(), md)
|
||||
|
||||
// get peer from context
|
||||
if p, ok := peer.FromContext(stream.Context()); ok {
|
||||
md["Remote"] = p.Addr.String()
|
||||
ctx = peer.NewContext(ctx, p)
|
||||
}
|
||||
|
||||
// set the timeout if we have it
|
||||
if len(to) > 0 {
|
||||
if n, err := strconv.ParseUint(to, 10, 64); err == nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user