zoukankan      html  css  js  c++  java
  • Golang gRPC调试工具

    Golang gRPC调试工具

    项目源码地址:https://github.com/fullstorydev

    1. 命令行工具 grpcurl

    1.1 安装

    $ go get github.com/fullstorydev/grpcurl
    $ go install github.com/fullstorydev/grpcurl/cmd/grpcurl
    

    安装完成后,会在$GOPATH/bin目录下,生成grpcurl可执行文件。

    1.2 验证

    $ grpcurl -version
    grpcurl 1.3.2 # 输出版本号,说明安装成功,如果不成功,查看是否将存放grpcurl的文件夹设置到env中
    

    1.3 注册反射

    使用前在main.go中添加反射

    // 注册反射, s为grpc server
    reflection.Register(s)
    

    1.4 使用示例

    -d表示传参,Ys.Pb.ChituSms.ChituSmsServ/GetMobileArea分别表示命名空间+service名称+方法名

    $ grpcurl -plaintext -d '{"PhoneNum":"13523456666"}' 127.0.0.1:8105 Ys.Pb.ChituSms.ChituSmsServ/GetMobileArea
    
    {
      "status": {
        "logid": "1233268494511693824"
      },
      "data": {
        "PhoneNum": "13523456666",
        "Province": "河南",
        "City": "郑州",
        "ZipCode": "450000",
        "AreaZone": "0371",
        "CardType": "中国移动"
      }
    }
    

    2. web调试工具grpcui

    2.1 安装

    go get github.com/fullstorydev/grpcui
    go install github.com/fullstorydev/grpcui/cmd/grpcui
    

    安装完成后,会在$GOPATH/bin目录下,生成grpcui可执行文件。

    2.2 验证

    $ grpcui -help
    

    2.3 注册反射

    使用前在main.go中添加反射

    // 注册反射, s为grpc server
    reflection.Register(s)
    

    2.4 运行

    $ grpcui -plaintext localhost:8001     
    gRPC Web UI available at http://127.0.0.1:37719/
    

    在浏览器中访问:http://127.0.0.1:37719/

    image-20210528111225961

    选择需要请求的service和method,填写request data后Invoke发送请求即可。

  • 相关阅读:
    golang linux安装
    vscode 插件
    windows访问eks pods
    go mod包管理
    beego创建项目
    Atcoder ARC-125
    AtCoder AGC003 简要题解
    Python 字符串转成变量名
    13_Go基础(binary)
    12_Go基础(iota)
  • 原文地址:https://www.cnblogs.com/zj420255586/p/14885552.html
Copyright © 2011-2022 走看看