gRPC调试工具推荐

2022-11-06 09:49:17 浏览数 (1)

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

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

Postman

这个我觉得是最好的

gRPC UI

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

安装

代码语言:javascript复制
go install github.com/fullstorydev/grpcui/cmd/grpcui@latest

使用

代码语言:javascript复制
# no TLS
cuiwei@weideMacBook-Pro ~ % grpcui -plaintext localhost:9087
gRPC Web UI available at http://127.0.0.1:61784/

Evans

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

安装

代码语言:javascript复制
go install github.com/ktr0731/evans@latest

使用

代码语言:javascript复制
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

安装

代码语言:javascript复制
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

使用

代码语言:javascript复制
# 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"
}

0 人点赞