Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Representing collections

What's more, protocol buffers can also model two types of collections, namely, lists and maps. To create a list of items, all we need to do is add the repeated keyword as a prefix of the field's type. On the other hand, maps are defined with a special notation, that is, map<K, V>, where K and V represent the types for the map keys and values. The following snippet is an example of defining collections:

message User {  string id = 1;  string name = 2;}message Users {  repeated User user_list = 1;  map<string, User> user_by_id = 2;}

When compiled to Go code, the fields for the Users message will be mapped to a []User type and a map[string]User type, respectively.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content