Skip to Content
Building RESTful Web services with Go
book

Building RESTful Web services with Go

by Naren Yellavula
December 2017
Intermediate to advanced
316 pages
6h 58m
English
Packt Publishing
Content preview from Building RESTful Web services with Go

Enumerations and repeated fields

Enumerations provide the ordering of numbers for a given set of elements. The default order of values is from zero to n. So, in protocol buffer messages, we can have an enumeration type. Let us see an example of the enum:

syntax 'proto3'; message Schedule{  enum Days{     SUNDAY = 0;     MONDAY = 1;     TUESDAY = 2;     WEDNESDAY = 3;     THURSDAY = 4;     FRIDAY = 5;     SATURDAY = 6;  }}

What if we need to assign the same values for the multiple enumeration members. Protobuf3 allows an option called allow aliases to assign two different members the same value. For example:

enum EnumAllowingAlias {
  option allow_alias = true;
  UNKNOWN = 0;
  STARTED = 1;
  RUNNING = 1;
}

Here, STARTED and RUNNING both have a 1 tag. This means that both can ...

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 RESTful Web Services with Go - Second Edition

Hands-On RESTful Web Services with Go - Second Edition

Naren Yellavula
Microservices with Go

Microservices with Go

Alexander Shuiskov

Publisher Resources

ISBN: 9781788294287Supplemental Content