GRPC: Client ID or connection information?

后端 未结 2 411
情话喂你
情话喂你 2021-01-12 12:59

Is there a way to get the connection information on RPC calls from server side? Or maybe something like unique client ID?

2条回答
  •  心在旅途
    2021-01-12 13:35

    gRPC now provide peer information (https://github.com/grpc/grpc-go/issues/334)

    import ( "google.golang.org/grpc/peer" )

    func (s *server) Hello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
      //p includes connection information
      p, ok := peer.FromContext(ctx)
      ....
      ....
    }
    

提交回复
热议问题