Skip to content

Instantly share code, notes, and snippets.

@syossan27
Last active April 24, 2019 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syossan27/1cb2e8bf59008a7150d12cc84a3f00fa to your computer and use it in GitHub Desktop.
Save syossan27/1cb2e8bf59008a7150d12cc84a3f00fa to your computer and use it in GitHub Desktop.
func (s *server) Example(ctx context.Context, in *pb.Request) (*pb.Response, error) {
// Server側のページネーションメッセージ
paginationMessage := &pb.ServerPaginationMessage{
Page: 2,
Limit: 20,
Size: 100,
First: &pb.PaginationMessage{ Page: 1, Limit: 20 },
Last: &pb.PaginationMessage{ Page: 5, Limit: 20 },
Next: &pb.PaginationMessage{ Page: 3, Limit: 20 },
Prev: &pb.PaginationMessage{ Page: 1, Limit: 20 },
}
// ページネーションメッセージをシリアライズし、Any型に埋め込む
serialized, err := proto.Marshal(paginationMessage)
if err != nil {
return nil, err
}
paginationAnyMessage = &any.Any{
TypeUrl: proto.MessageName(paginationMessage),
Value: serialized,
}
return &pb.Response{
Pagination: paginationAnyMessage,
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment