4 Microservice project setup

 

This chapter covers

  • Using hexagonal architecture for microservice projects
  • Setting up tool kits for services
  • Running a basic microservice application
  • Making the initial request for running an application

It is very normal to ask, “How should I structure my project?” before writing the first line of your Go microservice project. The answer to this question might seem difficult initially, but it is easy to apply some common software architecture patterns that help solve challenges such as building modular projects to have testable components. Let’s see how to apply those principles to a Go microservice project and perform some tests to see how gRPC endpoints work.

4.1 Hexagonal architecture

Hexagonal architecture (https://alistair.cockburn.us/hexagonal-architecture/), proposed by Alistair Cockburn in 2005, is an architectural pattern that aims to build loosely coupled application components that can be connected via ports and adapters. In this pattern, the consumer opens the application at a port via an adapter, and the output is sent through a port to an adapter. Therefore, hexagonal architecture is also known as a ports and adapters system. Using ports and adapters creates an abstraction layer that isolates the application’s core from external dependencies. Now that we understand the general components of hexagonal architecture, let’s dive deeper into each.

4.1.1 Application

4.1.2 Actors

4.1.3 Ports

4.1.4 Adapters

4.2 Order service implementation

4.2.1 Project folders

4.2.2 Initializing a Go project

4.2.3 Implementing the application core

4.2.4 Implementing ports

4.2.5 Implementing adapters

4.2.6 Implementing a gRPC adapter

4.2.7 Dependency injection and running the application

4.2.8 Calling a gRPC endpoint