Search code examples
gogrpcgrpc-go

Sending ListBlog response in unary streaming


I am trying to return list of items from grpc without streaimg API and not finding any solution or example , I know we use this kind of proto file when using streaming

message ListBlogResponse {
    Blog blog = 1;
}

and then Blog

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

but I want to send response once without using any streaming some thing like this :

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

what will be the protofile for this ?


Solution

  • You need a message containing multiple blogs:

    message BlogEntries {
       repeated Blog blog = 1;
    }
    

    Then you can return:

    return &BlogEntries{Blog:entries},nil