grpc生成pb.go以及grpc.pb.go文件遇到的问题

grpc生成pb.go以及grpc.pb.go文件遇到的问题,第1张

1.生成pb.go(Linux 平台)

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    helloworld/helloworld.proto

2.生成pb.go(Windows平台)

protoc 默认不支持go语言文件的输出,需按插件的形式来实现
通过protoc命令生成  xx.pb.go (数据结构的定义,及 *** 作方法)
protoc  --plugin=protoc-gen-go.exe   --go_out=.    xx.proto

通过protoc命令生成  xx_grpc.pb.go (自动生成rpc通讯相关的代码)
protoc  --plugin=protoc-gen-go.exe   --go-grpc_out=.    xx.proto

若提示: --go-grpc_out: protoc-gen-go-grpc: 系统找不到指定的文件。

需在 grpc-go\cmd\protoc-gen-go-grpc 进行编译, go build即可。 把生成的protoc-gen-go-grpc.exe放到你的  GOPATH/bin 目录下

批处理proto生成XX.pb.go以及XX_grpc.pb.go

第一个生成XX_grpc.pb.go
第二个生成XX.pb.go

set proto_name=%~nx1
protoc  -I=./  --go-grpc_out=./  --plugin=protoc-gen-grpc=./protoc-gen-go.exe  %proto_name%
protoc  -I=./  --go_out=./  --plugin=./protoc-gen-go.exe  %proto_name%
Missing input file 的Protocol 报错解决
prop.proto冒号后面那个点和文件名之间有个空格,忘记加空格了不会编译通过,会报错:Missing input file.

https://www.cnblogs.com/yinzhengjie2020/p/12741943.html

文中脚本以及工具:
脚本以及工具链接

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/994282.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存