Building Distributed Applications in Gin
A hands-on guide for Go developers to build and deploy distributed web apps with the Gin framework
Mohamed Labouardy
BIRMINGHAMMUMBAI
Building Distributed Applications in Gin
Copyright 2021 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Kunal Chaudhari
Acquisition Editor: Denim Pinto
Publishing Product Manager: Ashish Tiwari
Senior Editor: Rohit Singh
Content Development Editor: Ananya Endow
Technical Editor: Gaurav Gala
Copy Editor: Safis Editing
Project Coordinator: Deeksha Thakkar
Proofreader: Safis Editing
Indexer: Vinayak Purushotham
Production Designer: Joshua Misquitta
Published: June 2021
Production reference: 1220621
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80107-485-8
www.packt.com
I want to thank my wife, Mounia. You've always supported me, always patiently listened while I struggled to get this done, and always made me believe I could finish this. I love you.
Thanks as well to all the folks at Packt who worked with me on the production and promotion of the book. It was truly a team effort.
Contributors
About the author
MohamedLabouardy is the CTO and cofounder of Crew.work, and a DevSecOps evangelist. He is the founder of Komiser.io, a regular conference speaker, and the author of several books about serverless and distributed applications.
You can find him on Twitter (@mlabouardy).
This book is dedicated to my parents, even though they will never know unless someone tells them about this.
About the reviewer
Dmitry Goryunov was born in 1987 in Tomsk, a really nice city in Siberia that many talented engineers call their home. His first coding experience was writing macros for Ultima Online at the age of 12.
Ever since 2007, throughout his entire career, he has enjoyed building distributed software systems. Currently, he lives in Berlin and works for Zalando SE, where he is solving MLOps challenges for natural language processing systems.
Preface
Gin is a high-performance HTTP web framework used to build web applications and microservices in Go. This book is designed to teach you the ins and outs of the Gin framework with the help of practical examples.
You'll start by exploring the basics of the Gin framework, before progressing to build a real-world RESTful API. Along the way, you'll learn how to write custom middleware and understand the routing mechanism, as well as how to bind user data and validate incoming HTTP requests. The book also demonstrates how to store and retrieve data at scale with a NoSQL database such as MongoDB, and how to implement a caching layer with Redis. Next, you'll understand how to secure and test your API endpoints with authentication protocols such as OAuth 2 and JWT. Later chapters will guide you through rendering HTML templates on the server side and building a frontend application with the React web framework to consume API responses. Moreover, you'll deploy your application on