将 fiber 作为 gRPC 服务器客户端的示例。
一个演示如何将 fiber 作为 gRPC 服务器客户端的示例程序。
先决条件
- Go 1.16 或更高版本
- Go 模块
设置
-
克隆仓库
git clone https://github.com/gofiber/recipes.git
cd recipes/grpc -
安装依赖
go mod tidy
运行应用
-
运行 gRPC 服务器
go run server/main.go
-
运行 Fiber 客户端
go run client/main.go
-
服务器将在
http://localhost:3000
启动。
端点
方法 | URL | 返回值 |
---|---|---|
GET | /add/:a/:b | a + b |
GET | /mult/:a/:b | a * b |
输出
-> curl http://localhost:3000/add/33445/443234
{"result":"476679"}
-> curl http://localhost:3000/mult/33445/443234
{"result":"14823961130"}
附加信息
gRPC (gRPC Remote Procedure Calls) 是一个由 Google 最初开发的高性能、开源的通用 RPC 框架。它使用 HTTP/2 作为传输协议,Protocol Buffers 作为接口描述语言,并提供诸如身份验证、负载均衡等特性。
欲了解更多信息,请访问官方 gRPC 文档。