在一元流中发送 ListBlog 响应

Sending ListBlog response in unary streaming

我正在尝试 return grpc 中的项目列表而不使用 streaimg API 并且没有找到任何解决方案或示例,我知道我们在使用流式处理时使用这种 proto file

message ListBlogResponse {
    Blog blog = 1;
}

然后是Blog

message Blog {
    string id = 1;
    string author_id = 2;
    string title = 3;
    string content = 4;
} 
     

但我想在不使用任何流媒体的情况下发送一次响应,就像这样:

return &api.ListBlogResponse{
        Blog: items,
    }, nil

这个的原型是什么?

您需要一条包含多个博客的消息:

message BlogEntries {
   repeated Blog blog = 1;
}

那么你可以return:

return &BlogEntries{Blog:entries},nil