主要参考了这篇帖子:https://segmentfault.com/a/1190000009277748
1.下载windows版本的PB
https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-win64.zip
配置好环境变量PATH
2.下载golang中对应的库
go get github.com/golang/protobuf/proto
go get github.com/golang/protobuf/protoc-gen-go
cd C:Usersahfuzhanggopkgmodgithub.comgolangprotobuf@v1.4.0protoc-gen-go
go install
在C:Usersahfuzhanggoin目录有protoc-gen-go.exe了
3.测试的proto文件:test.proto
syntax = "proto3"; //指定版本,必须要写(proto3、proto2)
package proto;
option go_package = "go_my_server/hs";
enum FOO
{
X = 0;
};
//message是固定的。UserInfo是类名,可以随意指定,符合规范即可
message UserInfo{
string message = 1; //消息
int32 length = 2; //消息大小
int32 cnt = 3; //消息计数
}
4.代码生成
protoc --plugin=protoc-gen-go.exe --go_out=./ test.proto