#Handler Layer
5 articles
11 Add Unit Tests Using Mockery
At this stage we will need the following dependencies
brew install mockery
go get github.com/stretchr/testify
go mod tidy
go mod vendor
go get github.com/DATA-DOG/go-sqlmock
In this project we will try to create unit tests using a mocking library with the name mockery
. This library is widely used by golang developers because of its ease of use and has the advantage of features that can cover all the necessary unit tests. If you have used unit tests in golang, you may already know this library but if you want to get more references, Santekno has also provided previous posts including:
10 Adding Simple Authentication
At this stage we will try to add simple Authentication by using middleware in Golang. You need to know that middleware is the process of intercepting an API which before the service when accessed goes to the *handler * layer, it will pass through this * middleware * layer (which we will create) to capture and process something for certain needs. For example, in this case we will intercept the service process to see if the API has a header with the key condition X-API-Key
.
09 Configuring HTTP Router, HTTP Server and Database Connection
At this stage we will create the main
function of the project that we have created. In the main
function we will add several function initializations which are used to initialize all the resources
needed by the project such as database connections, handler initialization, usecases and repositories that we have previously created.
08 Adding a Request Validator Using Golang Playground
At this stage we will add validation for each request sent to the API Application on our Services for example on add, change and delete requests. The validation we use is package github.com/go-playground/validator.
07 Creating a Handler as a Data Delivery Layer
At this stage we will continue the project that we have created by creating a Delivery Layer. This layer as explained earlier is a layer that connects user requests with the logic layer.