【Mac 安装使用protobuf】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
推荐阅读
- Go|Docker后端部署详解(Go+Nginx)
- GO|GO,GO,GO!
- Go成长之路|go中判断空字符串、nil和len(t)的用法
- go编译tools
- go grpc安装与使用
- goroutine 调度原理
- Go|Go进阶之路——复杂类型
- Go进阶之路——变量
- Go进阶之路——流程控制语句