add peer in context
This commit is contained in:
parent
d09a33b43c
commit
5a7113b669
7
grpc.go
7
grpc.go
@ -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…
Reference in New Issue
Block a user