avatarIsrael Josué Parra Rosales

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3531

Abstract

define the microservices worked on in this chapter will be taken as a starting point reviewed in the previous chapter. From this chapter, we are going to start adding progressively the learned in this and the future chapters, our objective is to cover all the topics practically.</p><p id="49fc">To enhance the clarity of this chapter, we have chosen to focus primarily on the most intricate microservice: the “<b>Shopping Cart</b>” This decision is deliberate and aimed at ensuring a comprehensive understanding of the key concepts covered throughout this chapter. By implementing and thoroughly analyzing this complex microservice, we will effectively address all the critical topics and principles defined for this chapter.</p><p id="dfda">By the end of this chapter, you’ll have gained a hands-on understanding of translating theory into practice, constructing microservices with a robust codebase, and integrating essential tools to streamline development, testing, and deployment. So, let’s dive in and embark on this journey of practical microservices implementation.</p><h1 id="5d71">Defining the technologies</h1><p id="cf83">Embarking on our step-by-step journey of crafting code, our very first milestone is to make strategic decisions regarding the technologies that will underpin our project. These choices are pivotal, as they will lay the groundwork for our microservices, aligning seamlessly with their functionalities and requirements.</p><p id="742d">Taking cues from the e-commerce microservices we explored in the previous chapter, we are now presented with the opportunity to curate a selection of frameworks and libraries tailored precisely to our needs.</p><p id="3839">Let’s proceed by listing and briefly introducing the technologies that will play a fundamental role in our project:</p><h2 id="694d">Gin-Gonic: A Powerful Web Framework</h2><p id="1ba7">Gin-Gonic is a robust web framework built in Go, designed to streamline the development of RESTful web applications and services. It boasts rapid routing capabilities and an extensive set of features tailored for efficient HTTP request and response management.</p><p id="3c63">For a deeper dive into this framework, you can explore its official documentation<b> <a href="https://github.com/gin-gonic/gin.">https://github.com/gin-gonic/gin</a></b><a href="https://github.com/gin-gonic/gin.">.</a></p><h2 id="a176">Configuration Management Made Simple with Configor</h2><p id="611b"><b>Configor</b> is a powerful Go library engineered to simplify the loading and administration of application configurations from diverse sources, including JSON files, YAML files, and environment variables. It plays a crucial role in maintaining the organization and accessibility of your application’s settings.</p><p id="95c6">For a more comprehensive understanding of this library, explore its official documentation <a href="https://github.com/jinzhu/configor."><b>https://github.com/jinzhu/configor</b>.</a></p><h2 id="6608">Data Validation Made Easy with Ozzo-validation</h2><p id="7c22">Ozzo-validation is a dynamic validation library tailored for Go applications. It empowers you to define meticulous validation rules for your data structures, guaranteeing that your data consistently adheres to your predefined specifications. This invaluable tool acts as a guardian of data integrity within your application, reinforcing its reliability and robustness.</p><p id="9f2d">For a more comprehensive understanding of this library, explore its official documentation

Options

<a href="https://github.com/go-ozzo/ozzo-validatio."><b>https://github.com/go-ozzo/ozzo-validatio</b>.</a></p><h2 id="55f2">Elevate Your Logging Experience with Logrus</h2><p id="46f2">Logrus stands as a high-powered logging library meticulously crafted for Go. This formidable tool not only simplifies logging but also ushers in advanced tracking capabilities. It empowers you to create structured and tailored logs, customized to your specific needs, making them indispensable for both application monitoring and debugging.</p><p id="9a76">For an in-depth exploration of this framework, dive into its official documentation available at <a href="https://github.com/sirupsen/logrus."><b>https://github.com/sirupsen/logrus</b>.</a></p><h2 id="02ba">Unlocking the Power of OpenAPI Documentation with Swaggo</h2><p id="bb46">Swaggo emerges as a remarkable utility designed to effortlessly generate OpenAPI documentation for web applications crafted in Go. With Swaggo by your side, documenting your API becomes an efficient endeavor. It empowers you to encapsulate crucial details like routes, parameters, responses, and real-world examples, rendering your API comprehensible and readily adaptable.</p><p id="a82f">For an immersive exploration of this framework, delve into its comprehensive official documentation, available <a href="https://github.com/swaggo/swag"><b>https://github.com/swaggo/swag</b></a></p><h2 id="d218">Empowering Testing with Gomock and mockgen</h2><p id="1d64">Gomock emerges as a stalwart testing framework within the Go ecosystem, expertly crafted to usher in the era of mocks. It simplifies the creation and management of mock interfaces, an essential asset for unit testing. With Gomock, you’re ensured that method calls conform precisely to expectations during testing, enhancing your confidence in the codebase’s reliability.</p><p id="d047">Mockgen is the indispensable companion to Gomock, seamlessly generating mock interfaces in Go. This tool automates the mock creation process, streamlining unit tests. Moreover, it’s a go-to choice for simulating external components, such as databases or web services, in meticulously controlled test environments.</p><p id="5c6b">To delve deeper into these remarkable tools, explore their official documentation ‘https://github.com/golang/mock'</p><p id="334b">These invaluable tools and libraries are instrumental in Go application development, enriching your code with efficiency, quality, and ease. They simplify crucial tasks such as API validation, configuration management, logging, testing, and documentation, thereby enhancing the overall development experience. In this chapter, we will implement each one of them and will be detailed to explain how it works and which are the best practices related to each one.</p><p id="0545">Next readings …</p><p id="9c5a">Wait for Chapter 10 “Building a Microservice With Go — Defining the Project Structure”.</p><div id="6cff" class="link-block"> <a href="https://readmedium.com/chapter-10-structuring-our-project-bc122f53315d"> <div> <div> <h2>Chapter 10-Structuring our project</h2> <div><h3>Building a Microservice with Go</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*LQ9vQXfI63lGuErnuwKoww.jpeg)"></div> </div> </div> </a> </div></article></body>

Chapter 9 -Building a Microservice with Go

Defining the technologies

The following list is the previous chapters of this series:

I recommend you take a look at the previous chapters if you have not read them yet. That will help you to get more knowledge in this wonderful world of “Microservices architecture”.

Structure

In this chapter, the following topics will be covered:

  • Defining the technologies

Introduction

In this chapter, we will delve into the hands-on aspects of crafting microservices — from defining the fundamental technologies to establishing a robust code structure and code deployment. We’ll explore the significance of a well-organized codebase, dive into the intricacies of software architecture, and learn to construct microservices that align with industry best practices. This chapter encompasses various crucial facets, each contributing to the holistic understanding of building and structuring microservices effectively.

To embark on the microservices journey, it’s essential to select the right set of technologies that resonate with your project’s goals. We’ll explore the key technologies that form the foundation of our microservices architecture

The importance of a well-structured project cannot be overstated. We’ll delve into the rationale behind a proper code organization and how it significantly impacts maintainability and collaboration. We’ll discuss how this practice simplifies development, debugging, and future enhancements.

Another essential point in this chapter is persistence since data persistence is a core aspect of microservices. We’ll learn how to establish connections with databases, focusing on implementing MySQL.

For the coding side, we have to play hand in hand with the code quality, we will explore the world of unit testing, defining tests, and applying the principles of Test-Driven Design.

To define the microservices worked on in this chapter will be taken as a starting point reviewed in the previous chapter. From this chapter, we are going to start adding progressively the learned in this and the future chapters, our objective is to cover all the topics practically.

To enhance the clarity of this chapter, we have chosen to focus primarily on the most intricate microservice: the “Shopping Cart” This decision is deliberate and aimed at ensuring a comprehensive understanding of the key concepts covered throughout this chapter. By implementing and thoroughly analyzing this complex microservice, we will effectively address all the critical topics and principles defined for this chapter.

By the end of this chapter, you’ll have gained a hands-on understanding of translating theory into practice, constructing microservices with a robust codebase, and integrating essential tools to streamline development, testing, and deployment. So, let’s dive in and embark on this journey of practical microservices implementation.

Defining the technologies

Embarking on our step-by-step journey of crafting code, our very first milestone is to make strategic decisions regarding the technologies that will underpin our project. These choices are pivotal, as they will lay the groundwork for our microservices, aligning seamlessly with their functionalities and requirements.

Taking cues from the e-commerce microservices we explored in the previous chapter, we are now presented with the opportunity to curate a selection of frameworks and libraries tailored precisely to our needs.

Let’s proceed by listing and briefly introducing the technologies that will play a fundamental role in our project:

Gin-Gonic: A Powerful Web Framework

Gin-Gonic is a robust web framework built in Go, designed to streamline the development of RESTful web applications and services. It boasts rapid routing capabilities and an extensive set of features tailored for efficient HTTP request and response management.

For a deeper dive into this framework, you can explore its official documentation https://github.com/gin-gonic/gin.

Configuration Management Made Simple with Configor

Configor is a powerful Go library engineered to simplify the loading and administration of application configurations from diverse sources, including JSON files, YAML files, and environment variables. It plays a crucial role in maintaining the organization and accessibility of your application’s settings.

For a more comprehensive understanding of this library, explore its official documentation https://github.com/jinzhu/configor.

Data Validation Made Easy with Ozzo-validation

Ozzo-validation is a dynamic validation library tailored for Go applications. It empowers you to define meticulous validation rules for your data structures, guaranteeing that your data consistently adheres to your predefined specifications. This invaluable tool acts as a guardian of data integrity within your application, reinforcing its reliability and robustness.

For a more comprehensive understanding of this library, explore its official documentation https://github.com/go-ozzo/ozzo-validatio.

Elevate Your Logging Experience with Logrus

Logrus stands as a high-powered logging library meticulously crafted for Go. This formidable tool not only simplifies logging but also ushers in advanced tracking capabilities. It empowers you to create structured and tailored logs, customized to your specific needs, making them indispensable for both application monitoring and debugging.

For an in-depth exploration of this framework, dive into its official documentation available at https://github.com/sirupsen/logrus.

Unlocking the Power of OpenAPI Documentation with Swaggo

Swaggo emerges as a remarkable utility designed to effortlessly generate OpenAPI documentation for web applications crafted in Go. With Swaggo by your side, documenting your API becomes an efficient endeavor. It empowers you to encapsulate crucial details like routes, parameters, responses, and real-world examples, rendering your API comprehensible and readily adaptable.

For an immersive exploration of this framework, delve into its comprehensive official documentation, available https://github.com/swaggo/swag

Empowering Testing with Gomock and mockgen

Gomock emerges as a stalwart testing framework within the Go ecosystem, expertly crafted to usher in the era of mocks. It simplifies the creation and management of mock interfaces, an essential asset for unit testing. With Gomock, you’re ensured that method calls conform precisely to expectations during testing, enhancing your confidence in the codebase’s reliability.

Mockgen is the indispensable companion to Gomock, seamlessly generating mock interfaces in Go. This tool automates the mock creation process, streamlining unit tests. Moreover, it’s a go-to choice for simulating external components, such as databases or web services, in meticulously controlled test environments.

To delve deeper into these remarkable tools, explore their official documentation ‘https://github.com/golang/mock'

These invaluable tools and libraries are instrumental in Go application development, enriching your code with efficiency, quality, and ease. They simplify crucial tasks such as API validation, configuration management, logging, testing, and documentation, thereby enhancing the overall development experience. In this chapter, we will implement each one of them and will be detailed to explain how it works and which are the best practices related to each one.

Next readings …

Wait for Chapter 10 “Building a Microservice With Go — Defining the Project Structure”.

Golang
Software Development
Software Architecture
Computer Science
Programming Languages
Recommended from ReadMedium