https://www.cnblogs.com/hacker-linner/p/14618862.html
https://www.lixueduan.com/posts/grpc/07-grpc-gateway/
https://www.bilibili.com/video/BV1q14y1j7nA
https://www.bilibili.com/video/BV13d4y1t7r8
之前网易的配置下发项目,用的就是这东西
即新的go-template就是基于grpc-gateway
gRPC-Gateway的作用
给grpc生成的文件附加一个http 1.1的restful供外界访问
安装
1 | go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest |
下载gRPC-Gateway需要的两个proto
Adding gRPC-Gateway annotations to an existing proto file
在项目里建一个 google/api目录,把这两个文件拷进去
在原本的Service那里新增一个
1 | option(google.api.http)={ |
其中option(google.api.http)=是固定写法
1 | protoc -I ./proto \ |
(相较之前多了--grpc-gateway_out ./proto --grpc-gateway_opt paths=source_relative这么一行)
-I是指定pb所在的路径
之后会生成一个xxx.pb.gw.go文件
mux是grpc提供的一个东西
原文链接: https://dashen.tech/2021/02/05/gRPC-Gateway的使用/
版权声明: 转载请注明出处.