[Go] protobuffer 的环境配置

一般使用gprc是需要使用protobuf作为数据传输的格式标准,可以对要传输的对象结构体进行序列化

先安装protoc,找到对应版本,下载直接把二进制文件复制到环境变量可以访问到的地方就行

https://github.com/protocolbuffers/protobuf/releases

安装go的依赖包和工具

git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc

git clone https://github.com/golang/protobuf.git $GOPATH/src/github.com/golang/protobuf

go install github.com/golang/protobuf/protoc-gen-go

创建文件比如orders.proto,required必填 ,后面那个1和2是字段顺序

syntax = "proto2";

message Orders {

required int32 order_id=1;

required string title=2;

}