1.使用brew安裝protoc
brew install protobuf
查看安裝結果
protoc --version
2.編輯protobuf文件
syntax = "proto3";
package message;
message OrderRequest {
string orderId = 1;
int64 timeStamp = 2;
}
message OrderInfo {
string OrderId = 1;
string OrderName = 2;
string OrderStatus = 3;
}
3.生成go文件
protoc message.proto --go_out=/message/
如果提示
protoc-gen-go: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.
執行命令:
go get -a github.com/golang/protobuf/protoc-gen-go