//版本
syntax = "proto3";
//引入包名
package go.micro.service.product;
//rpc里面的调用 定义服务
service Product{
rpc AddProduct(ProductInfo) returns(ResponseProduct){}
}
//消息格式
message ProductInfo {
//这个id=1不是赋值,是字段标识符,前面还有一个修饰符在proto3里面,可以省略不写。
//后面一定要打上分号,常用的标识符是1-15,超过15会用2个字节来存字段
int64 id = 1;
string product_name = 2;
}
message ResponseProduct{
//每个message里面标识符都可以从1开始
int64 product_id = 1;
}
需要安装好proto, 如果使用gRPC那就在当前目录CMD中输入
protoc 文件名.proto --go__out=plugins=grpc:.
然后就会得到一个 文件名.pb.go的文件了