grpc根据proto文件自动生成go源码


grpc根据proto文件自动生成go源码

安装protoc工具

https://github.com/protocolbuffers/protobuf/releases下载protobuf的编译器protoc,windows上可以直接下到exe文件(linux则需要编译),最后将下载好的可执行文件拷贝到$GOPATH的bin目录下($GOPATH/bin目录最好添加到系统环境变量里)

linux环境,下载protoc源码,下载地址,我选择如图的安装包,可以不需要再编译,直接将bin添加到环境变量中或者将bin/protoc 软链接到/usr/bin下。

提示:官方或非官方的protobuf,二选一即可,都下载也不会冲突。

下载官方protobuf插件

git clone https://github.com/protocolbuffers/protobuf-go.git ./google.golang.org/protobuf

下载非官方gogoprotobuf插件

go get github.com/gogo/protobuf/protoc-gen-gofast

官方的生成protoc-gen-go.exe

go install google.golang.org/protobuf/cmd/protoc-gen-go/

根据proto文件自动生成test.pb.go

protoc --go_out=plugins=grpc:.\ .\test.proto

protoc --gofast_out=plugins=grpc:./ ./test.proto

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM