Work with the Generated Code
Although the generated code in log.pb.go is a lot longer than your handwritten code in log.go (because of the extra code needed to marshal to the protobuf binary wire format), you’ll use the code as if you’d handwritten it. For example, you’ll create instances using the & operator (or new keyword) and access fields using a dot.
The compiler generates various methods on the struct, but the only methods you’ll use directly are the getters. Use the struct’s fields when you can, but you’ll find the getters useful when you have multiple messages with the same getter(s) and you want to abstract those method(s) into an interface. For example, imagine you’re building a retail site like Amazon and have different types of ...
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.
Read now
Unlock full access