Book Image

Building Distributed Applications in Gin

By : Mohamed Labouardy
4 (1)
Book Image

Building Distributed Applications in Gin

4 (1)
By: Mohamed Labouardy

Overview of this book

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. Finally, you’ll deploy your application on Amazon Web Services (AWS) and learn how to automate the deployment process with a continuous integration and continuous delivery (CI/CD) pipeline. By the end of this Gin book, you will be able to design, build, and deploy a production-ready distributed application from scratch using the Gin framework.
Table of Contents (16 chapters)
1
Section 1: Inside the Gin Framework
3
Section 2: Distributed Microservices
9
Section 3: Beyond the Basics

Building an HTTPS server

So far, the API is served locally through HTTP, but for a real-world application, it should be served under a domain name through HTTPS.

To set this up, proceed as follows:

  1. Use the ngrok solution to serve our local web API with a public Uniform Resource Locator (URL) that supports both HTTP and HTTPS.

    Note

    In advanced chapters, we will explore how to purchase a domain name and set up HTTPS for free on a cloud provider such as Amazon Web Services (AWS).

  2. Download the ZIP file based on your operating system (OS) from the official Ngrok page at https://ngrok.com/download. In this book, we will work with version 2.3.35. Once downloaded, unzip Ngrok from a terminal with the following commands:
    unzip ngrok-stable-darwin-amd64.zip
    cp ngrok /usr/local/bin/
    chmod +x /usr/local/bin/ngrok
  3. Verify if it's properly installed by executing the following command:
    ngrok version

    It should output the following message:

    Figure 4.30 – Ngrok version

  4. Configure...