0%

An effective guide to learning how to build a large-scale distributed application using the wide range of functionalities in Gin

Key Features

  • Explore the commonly used functionalities of Gin to build web applications
  • Become well-versed with rendering HTML templates with the Gin engine
  • Solve commonly occurring challenges such as scaling, caching, and deployment

Book Description

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/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.

What you will learn

  • Build a production-ready REST API with the Gin framework
  • Scale web applications with event-driven architecture
  • Use NoSQL databases for data persistence
  • Set up authentication middleware with JWT and Auth0
  • Deploy a Gin-based RESTful API on AWS with Docker and Kubernetes
  • Implement a CI/CD workflow for Gin web apps

Who this book is for

This book is for Go developers who are comfortable with the Go language and seeking to learn REST API design and development with the Gin framework. Beginner-level knowledge of the Go programming language is required to make the most of this book.

Table of Contents

  1. Building Distributed Applications in Gin
  2. Contributors
  3. About the author
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  6. Section 1: Inside the Gin Framework
  7. Chapter 1: Getting Started with Gin
    1. Technical requirements
    2. What is Gin?
    3. Setting up the Go environment
    4. Linux/FreeBSD
    5. Windows
    6. MacOS
    7. Integrated development environment
    8. Installing Go tools
    9. Installing and configuring Gin
    10. Dependency management in Golang
    11. Writing a custom HTTP handler
    12. Summary
    13. Questions
    14. Further reading
  8. Section 2: Distributed Microservices
  9. Chapter 2: Setting Up API Endpoints
    1. Technical requirements
    2. Exploring API functionality
    3. Defining the data model
    4. HTTP endpoints
    5. Implementing HTTP routes
    6. POST /recipes
    7. GET /recipes
    8. PUT /recipes/{id}
    9. DELETE /recipes/{id}
    10. GET /recipes/search
    11. Writing the OpenAPI Specification
    12. Installing Go Swagger
    13. Swagger metadata
    14. Summary
    15. Questions
    16. Further reading
  10. Chapter 3: Managing Data Persistence with MongoDB
    1. Technical requirements
    2. Running a MongoDB Server
    3. Installing Docker CE
    4. Running a MongoDB container
    5. Configuring Go's MongoDB driver
    6. Exploring MongoDB queries
    7. The InsertMany operation
    8. The Find operation
    9. The InsertOne operation
    10. The UpdateOne operation
    11. Designing the project's layout
    12. Caching an API with Redis
    13. Running Redis in Docker
    14. Optimizing MongoDB queries
    15. Performance benchmark
    16. Summary
    17. Questions
    18. Further reading
  11. Chapter 4: Building API Authentication
    1. Technical requirements
    2. Exploring authentication
    3. Using API keys
    4. Introducing JWTs
    5. Sign-in HTTP handler
    6. Renewing a JWT
    7. Hashing and salting passwords
    8. Persisting client sessions and cookies
    9. Authenticating with Auth0
    10. Building an HTTPS server
    11. Self-signed certificates
    12. Summary
    13. Questions
    14. Further reading
  12. Chapter 5: Serving Static HTML in Gin
    1. Technical requirements
    2. Serving static files
    3. Rendering HTML templates
    4. Creating the view templates
    5. Creating reusable templates
    6. Building a self-contained web application
    7. Bundling static files
    8. Building a SPA
    9. Getting started with React
    10. Exploring React components
    11. Resolving cross-origin requests
    12. Summary
    13. Questions
    14. Further reading
  13. Chapter 6: Scaling a Gin Application
    1. Technical requirements
    2. Scaling workloads with a message broker
    3. Deploying RabbitMQ with Docker
    4. Exploring the Producer/Consumer pattern
    5. Scaling horizontally with Docker replicas
    6. Using Docker multi-stage builds
    7. Scaling services with Docker Compose
    8. Using the NGINX reverse proxy
    9. Caching assets with HTTP cache headers
    10. Setting HTTP caching headers
    11. Summary
    12. Further reading
  14. Section 3: Beyond the Basics
  15. Chapter 7: Testing Gin HTTP Routes
    1. Technical requirements
    2. Testing Gin HTTP handlers
    3. Generating code coverage reports
    4. Performing integration tests with Docker
    5. Discovering security vulnerabilities
    6. Gosec
    7. Securing Go modules with Snyk
    8. Running Postman collections
    9. Scripting in Postman
    10. Running collections with Newman
    11. Summary
    12. Questions
    13. Further reading
  16. Chapter 8: Deploying the Application on AWS
    1. Technical requirements
    2. Deploying on EC2 instance
    3. Launching an EC2 instance
    4. SSL offloading with an application load balancer
    5. Deploying on Amazon ECS
    6. Storing images in a private repository
    7. Creating an ECS cluster
    8. Deploying on Kubernetes with Amazon EKS
    9. Configuring kubectl
    10. Migrating a Docker Compose workflow to Kubernetes
    11. Summary
    12. Questions
    13. Further reading
  17. Chapter 9: Implementing a CI/CD Pipeline
    1. Technical requirements
    2. Exploring CI/CD practices
    3. Continuous integration
    4. Continuous deployment
    5. Continuous delivery
    6. Building a CI workflow
    7. Pipeline as Code
    8. Maintaining multiple runtime environments
    9. Implementing continuous delivery
    10. Improving the feedback loop with Slack
    11. Summary
    12. Questions
    13. Further reading
  18. Chapter 10: Capturing Gin Application Metrics
    1. Technical requirements
    2. Exposing Gin metrics with Prometheus
    3. Instrumenting a Gin application
    4. Monitoring server-side metrics
    5. Creating a Grafana notification channel
    6. Streaming Gin logs to the ELK platform
    7. Deploying the ELK stack with Docker
    8. Writing Grok expressions
    9. Updating the Gin logging format
    10. Summary
    11. Further reading
    12. Conclusion
  19. Assessments
    1. Chapter 1 – Getting started with Gin
    2. Chapter 2 – Setting up API Endpoints
    3. Chapter 3 – Managing Data Persistence with MongoDB
    4. Chapter 4 – Building API Authentication
    5. Chapter 5 – Serving Static HTML in Gin
    6. Chapter 7 – Testing Gin HTTP Routes
    7. Chapter 8 – Deploying the Application on AWS
    8. Chapter 9 – Implementing a CI/CD Pipeline
    9. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
3.134.102.182