获得服务回报的最佳方法是什么?我的意思是,我希望单个方法能够返回多个类型,在这种情况下,find方法将返回User或Response
syntax = "proto3";
service UserService {
rpc Add(User) returns (Response);
rpc Find(Id) returns (User);
}
message Response {
string message = 1;
}
message Id {
string id = 1;
}
message User {
string id = 1;
int32 money = 2;
}
您可以返回一个包含响应和用户的对象。
syntax = "proto3";
service UserService {
rpc Add(User) returns (Response);
rpc Find(Id) returns (FindResponse);
}
message Response {
string message = 1;
}
message Id {
string id = 1;
}
message User {
string id = 1;
int32 money = 2;
}
message FindResponse{
Response response = 1;
User user = 2;
}