Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Microservices with Go

You're reading from   Microservices with Go The expert's guide to building secure, scalable, and reliable microservices with Go

Arrow left icon
Product type Paperback
Published in Jun 2025
Publisher Packt
ISBN-13 9781836207337
Length 428 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Alexander Shuiskov Alexander Shuiskov
Author Profile Icon Alexander Shuiskov
Alexander Shuiskov
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Introduction
2. Introduction to Microservices FREE CHAPTER 3. Foundation
4. Scaffolding a Go Microservice 5. Service Discovery 6. Serialization 7. Synchronous Communication 8. Asynchronous Communication 9. Storing Service Data 10. Setting Up Service Deployments 11. Unit and Integration Testing 12. Security and Compliance 13. Maintenance
14. Reliability Overview 15. Collecting Service Telemetry Data 16. Setting Up Service Alerting 17. Performance Monitoring 18. Advanced Topics
19. Implementing Distributed System Scenarios 20. Advanced Topics 21. Other Books You May Enjoy
22. Index

Using Protocol Buffers

In this section, we are going to illustrate how you can use Protocol Buffers for your applications. We will use the microservice examples from the previous chapters and define our data model in Protocol Buffers format. Then, we will use code generation tools alongside Protocol Buffers to generate our data structures. Finally, we will illustrate how to use our generated code to serialize and deserialize our data.

First, let’s prepare our application. Create a directory called api under our application’s src directory. Inside this directory, create a movie.proto file and add the following to it:

syntax = "proto3";
option go_package = "/gen";
message Metadata {
    string id = 1;
    string title = 2;
    string description = 3;
    string director = 4;
}
message MovieDetails {
    double rating = 1;
    Metadata metadata = 2;
}

In the first line of our schema definition, we set the syntax to proto3, the latest version...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Visually different images