dounue1965 2019-05-04 22:39
浏览 400

如何解码被拦截的gRPC请求/响应,以查看golang中已发送/已接收的protobuf消息?

I am intercepting the raw gRPC requests/responses going across a UNIX socket (the containerd socket using the cri-api, using eBPF to perform the interception) and I want to work out what is being sent/received. I have access to the .proto file used to generate the gRPC interface using the gRPC plugin so this should be possible to do but I'm not sure how to start as I am not part the gRPC connection.

How can I go about doing this in golang?

  • 写回答

1条回答 默认 最新

  • dongqindan4406 2019-05-05 02:47
    关注
    1. Use GRPC basic support

    https://godoc.org/google.golang.org/grpc#StreamInterceptor

    https://godoc.org/google.golang.org/grpc#UnaryInterceptor

    1. Use GRPC middleware

    https://github.com/grpc-ecosystem/go-grpc-middleware

    1. The simple and stupid way
    // GRPC handler
    func (x *M) GRPCHanler(ctx context.Context, req *REQ) (rsp *RSP, eRR error) {
        rsp = new(RSP)
        method = "GRPCHanler"
        log.Infof("GRPC-%s Request:%+v", method, req)
        defer func() {
            log.Infof("GRPC-%s Response:%+v", method, rsp)
            if eRR != nil {
                log.Errorf("GRPC-%s Error:%v", method,eRR)
            }
            // eRR = nil
        }
        // handler
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题