syntax = "proto3";
option go_package = ".;proto"; //生成在当前目录下
package proto;
import "google/protobuf/struct.proto";
// service definition.
service HelloService {
rpc HelloInfo (Request) returns (Reply) {}
}
// The request message
message Request {
string id = 1;
repeated string type = 2;
repeated Data data = 3; //嵌套类型
}
message Data {
int id = 1;
}
// The response message
//grpc无法像http那也直接把未知对象赋值给interface的引用,需要解析为pb定义的具体结构,
//可以用google/protobuf/struct.proto中的struct接收object类型,然后在golang里面进行解析
message Reply {
google.protobuf.Struct respData = 1;
}
生成:protoc --go_out=plugins=grpc:. hello.proto