gRPC调试工具推荐

编辑于 2022-10-26 18:17 阅读 185

在介绍工具之前先说一个情况,就是你用某个工具调试时,会发现,有的项目无需手动导入.proto文件,工具就能列出所有method,有些则不行。这是因为项目注册了反射,先看下怎么注册反射

carbon.png

就是这样,下面开始介绍工具

Postman

这个我觉得是最好的

WX202210261439072x.jpg

gRPC UI

gRPC的交互式Web用户界面,类似postman

安装

go install github.com/fullstorydev/grpcui/cmd/grpcui@latest

使用

# no TLS
cuiwei@weideMacBook-Pro ~ % grpcui -plaintext localhost:9087
gRPC Web UI available at http://127.0.0.1:61784/

WX202210261405092x.jpg

Evans

Evans:更具表现力的通用gRPC客户端

安装

go install github.com/ktr0731/evans@latest

53423552e5ca88003a2411e99927fe7f3d5f867a.jpg

使用

cuiwei@weideMacBook-Pro ~ % evans -r repl --host localhost -p 9087

  ______
 |  ____|
 | |__    __   __   __ _   _ __    ___
 |  __|   \ \ / /  / _. | | '_ \  / __|
 | |____   \ V /  | (_| | | | | | \__ \
 |______|   \_/    \__,_| |_| |_| |___/

 more expressive universal gRPC client

blog.v1.BlogService@localhost:9087> show service
+-------------+---------------------+----------------------------+-----------------------------+
|   SERVICE   |         RPC         |        REQUEST TYPE        |        RESPONSE TYPE        |
+-------------+---------------------+----------------------------+-----------------------------+
| BlogService | AdminLogin          | AdminLoginRequest          | AdminLoginResponse          |
| BlogService | AdminFindpasswd     | AdminFindpasswdRequest     | AdminFindpasswdResponse     |
+-------------+---------------------+----------------------------+-----------------------------+

blog.v1.BlogService@localhost:9087> call AdminDetail
admin_id (TYPE_INT64) => 5
{
  "avatar": "data/upload/avatar/5.jpg",
  "createTime": "1662222060",
  "email": "test@qq.com",
  "id": "5",
  "init": "1",
  "mobile": "18666666666",
  "nickname": "nick2..",
  "status": "1",
  "updateTime": "1664943345",
  "username": "admin22"
}

gRPCurl

像cURL一样,但它属于gRPC:用于与gRPC服务器交互的命令行工具

https://github.com/fullstorydev/grpcurl

安装

go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

使用

# no TLS
cuiwei@weideMacBook-Pro ~ % grpcurl -plaintext -d '{"to_aid": 5}' localhost:9087 blog.v1.BlogService/Admin2Detail
{
  "id": "5",
  "username": "admin22",
  "nickname": "nick2..",
  "email": "test@qq.com",
  "mobile": "18666666666",
  "avatar": "data/upload/avatar/5.jpg",
  "init": "1",
  "status": "1",
  "createTime": "1662222060",
  "updateTime": "1664943345"
}

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验