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.