参照 golang开发一个简单的grpc[1]
完整代码:github.com/cuishuang/grpcdemo[2], 此处仅需要使用gRPC Server,不需要Client部分
切到 helloservice目录执行 go run main/main.go
![alt](https://i-blog.csdnimg.cn/blog_migrate/ea4955d2ad4a51ea47089152cf86edea.png)
grpcui
fullstorydev/grpcui[3]
go install github.com/fullstorydev/grpcui/cmd/grpcui@latest
grpcui -plaintext 127.0.0.1:1234
![alt](https://i-blog.csdnimg.cn/blog_migrate/1525df62e787fb092d5176ab1f533351.png)
参考调试工具_微服务实战之 Go gRPC 调试工具[4],在源码中加一行reflection.Register(s)
![alt](https://i-blog.csdnimg.cn/blog_migrate/b3cde3f00f6d7b2c8df677e8ec16e608.png)
重新启动Server
![alt](https://i-blog.csdnimg.cn/blog_migrate/aec6dbe16f7ef69a5f69abcb521a4704.png)
![alt](https://i-blog.csdnimg.cn/blog_migrate/bc7a0db3c3c3aaa3cd95d0867e6efce6.png)
![alt](https://i-blog.csdnimg.cn/blog_migrate/180e36502c8ce3e5308f80806a42938f.png)
grpcurl
grpcui底层其实就是grpcurl
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
或 brew install grpcurl
或使用Docker
# Download image
docker pull fullstorydev/grpcurl:latest
# Run the tool
docker run fullstorydev/grpcurl api.grpc.me:443 list
grpcurl -plaintext localhost:端口号 list
![alt](https://i-blog.csdnimg.cn/blog_migrate/97c27e540c2d542bdd2081f1acc9d657.png)
不如grpcui直观
Postman
![alt](https://i-blog.csdnimg.cn/blog_migrate/57caab3d691220982f89df75ddcf911d.png)
![alt](https://i-blog.csdnimg.cn/blog_migrate/374cdc2ab349f7e65eb8779025fd5518.png)
三種好用的 gRPC 測試工具[5]
另外类似的工具还有 Evans,BloomRPC (超实用的 gRPC 客户端调试工具[6])
参考资料
golang开发一个简单的grpc: https://waterflow.link/articles/1665674508275
[2]github.com/cuishuang/grpcdemo: https://github.com/cuishuang/grpcdemo
[3]fullstorydev/grpcui: https://github.com/fullstorydev/grpcui
[4]调试工具_微服务实战之 Go gRPC 调试工具: https://blog.csdn.net/weixin_39621178/article/details/112699562
[5]三種好用的 gRPC 測試工具: https://learnku.com/articles/71123
[6]超实用的 gRPC 客户端调试工具: https://zhuanlan.zhihu.com/p/424825387
本文由 mdnice 多平台发布