gateway+grpc+proto+etcd环境搭建安装

原创
2022/03/17 16:25
阅读数 71

1、Golang 环境配置

source ~/.bashrc
export GOPRIVATE=xxx.com    #你的私有库
export GOPROXY= https://goproxy.cn    #代理地址
export GOPATH=/root/src/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
 

2、安装 protoc 建议:3.11.4

brew install protobuf
protoc --version # libprotoc 3.17.3

3、安装 protoc-gen-go 建议:1.4.3

 
不过这时候又发现生成的gateway文件不对。

4、项目生成 .pb.go文件

protoc -I ./ -I $GOPATH/src -I $GOPATH/pkg/mod/ github.com/grpc-ecosystem/grpc-gateway@v1.16.0/third_party/googleapis --go_out=plugins=grpc:. --go_opt=paths=source_relative ./proto/*.proto

5、网关项目(grpcGateway)生成 .pd.go

protoc -I ./ -I $GOPATH/src -I $GOPATH/pkg/mod/ github.com/grpc-ecosystem/grpc-gateway@v1.16.0/third_party/googleapis --go_out=plugins=grpc:. --go_opt=paths=source_relative ./proto/*.proto

6、安装 protoc-gen-grpc-gateway 建议:2.6.0

7、网关项目(grpcGateway)生成 .pd.gw.go

protoc -I ./ -I $GOPATH/src -I $GOPATH/pkg/mod/ github.com/grpc-ecosystem/grpc-gateway@v1.16.0/third_party/googleapis --grpc-gateway_out=logtostderr=true:. --grpc-gateway_opt=logtostderr=true --grpc-gateway_opt=paths=source_relative ./proto/*.proto

8、proto文件生成shell

PROJECT_PROTO_FILE_PATH=$GOPATH/proto
protoc \
-I $PROJECT_PROTO_FILE_PATH \
-I $GOPATH/src \
-I $GOOGLE_API \
--go_out=plugins=grpc:$PROJECT_PROTO_FILE_PATH \
--go_opt=paths=source_relative $PROJECT_PROTO_FILE_PATH/*.proto
GATEWAY_PROTO_FILE_PATH=$GOPATH/grpcGateway/proto
cp -f $PROJECT_PROTO_FILE_PATH/xxx.proto $GATEWAY_PROTO_FILE_PATH/xxx.proto
protoc \
-I $GATEWAY_PROTO_FILE_PATH \
-I $GOPATH/src \
-I $GOOGLE_API \
--go_out=plugins=grpc:$GATEWAY_PROTO_FILE_PATH \
--go_opt=paths=source_relative $GATEWAY_PROTO_FILE_PATH/*.proto
protoc \
-I $GATEWAY_PROTO_FILE_PATH \
-I $GOPATH/src \ -I $GOOGLE_API \
--grpc-gateway_out=logtostderr=true:$GATEWAY_PROTO_FILE_PATH \
--grpc-gateway_opt=logtostderr=true \
--grpc-gateway_opt=paths=source_relative $GATEWAY_PROTO_FILE_PATH/*.proto
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部