共计 520 个字符,预计需要花费 2 分钟才能阅读完成。
下载 protoc
下载地址:https://github.com/protocolbuffers/protobuf/tags
在上面的地址中找到适合自己电脑的版本下载即可。
解压到 GOPATH 中
解压得到下面几个文件。
将 bin
目录中的 protoc.exe
文件 拷贝到电脑的 GOPATH
目录中的 bin
目录下即可。
命令行输入一下命令查看是否安装成功,记得将 GOPATH
下的 bin
目录添加到环境变量中。
protoc --version
安装 GO 的编译器插件
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
使用
protoc --go_out=. --go-grpc_out=. ./proto/user.proto
注:--go_out
指定生成的 xx.pb.go
文件存放的目录,--go-grpc_out
指定生成的 xx_grpc.pb.go
文件存放的目录。这两个参数可以配合 proto
文件中的 go_package
参数设置生成的文件存放地址。最后一个参数是 proto
文件的路径。
正文完
发表至: Go
2023-12-19