protobuf的使用

1 安装protobuf后,可以将写的go代码,进行转换

先执行go get github.com/golang/protobuf/protoc-gen-go,安装protoc-gen-go.exe,再执行安装protobuf,输入go get github.com/golang/protobuf/proto,安装protoc.exe,或 者将网易云微服务课程资料里的protoc.exe直接拷贝到gopath下的bin文件夹里,

在test.go目录下执行protoc --go_out=. test.proto 如果成功会生成test.pb.go文件

在win下有时候执行上述命令由于找不到protoc-gen-go插件,会报错:

ERROR: 2021/05/20 20:59:52 [profiling] error parsing flags: when -address isn't specified, you must
 include -stream-stats-catapult-json
--go_out: protoc-gen-go: Plugin failed with status code 1.

只需在命令行中加入protoc-gen-go插件的路径,https://www.stonebaby.net/?p=670

参考:https://studygolang.com/articles/15462

原文地址:https://www.cnblogs.com/xxswkl/p/14469610.html