sergicanet9 / go-hexagonal-api

REST API implementing Hexagonal Architecture (Ports & Adapters) making use of own scv-go-tools package.
MIT License
12 stars 1 forks source link
docker go hexagonal-architecture kubernetes mongodb postgresql restapi

go-hexagonal-api

CI CD Coverage Go Reference

REST API implementing Hexagonal Architecture (Ports & Adapters) making use of own scv-go-tools package.
It consists in a set of endpoints for user management that can indistinctly work with either a MongoDB or PostgreSQL instance, using the same handlers and business logic.

Provides:

Run it with docker

make up

It starts 4 containers. Two of them are databases (MongoDB and PostgreSQL) and the other two are instances of the API, each of them already set up to work with one of the databases.
Both Swagger URLs are printed when running the command.

Stop and remove the running containers

make down

Debug it with VS Code

Debugging configurations provided in launch.json for hitting both MongoDB and PostgreSQL containers. Just select the desired one in the VS Code´s build-in debugger and run it.
Then open http://localhost:{port}/swagger/index.html, where {port} is the value specified in launch.json for the selected configuration.

NOTES:

Run it with command line

    go run cmd/main.go --ver={version} --env={environment} --port={port} --db={database} --dsn={dsn}

or:

go build cmd/main.go
 ./main --ver={version} --env={environment} --port={port} --db={database} --dsn={dsn}

Provide the desired values to {version}, {environment}, {port}, {database}, {dsn}.
Then open http://localhost:{port}/swagger/index.html.

Run unit tests with code coverage

make test-unit

View coverage report

make cover

Run integration tests

make test-integration

NOTES:

(Re)Generate Swagger documentation

make swagger

(Re)Generate Mockery mocks

make mocks

Database commands for Postgres

Create new migration

make goose

Write the file name without ".sql" suffix and press enter. Then edit the newly created file to define the behavior of the migration.

Connect to database

psql "{dsn}"

Create new database

CREATE DATABASE {db_name};

Drop database (Azure Postgres Flexible Server)

az login
az postgres flexible-server db delete -g {resource_group} -s {resource_name} --database-name {db_name}

Dump database schema

pg_dump -h {host} -U {username} {db_name} --schema-only > dump.sql

Live AKS environments (turned off)

Dev

http://go-hexagonal-api-mongo-dev.westeurope.cloudapp.azure.com/swagger/index.html
http://go-hexagonal-api-postgres-dev.westeurope.cloudapp.azure.com/swagger/index.html

Author

Sergi Canet Vela

License

This project is licensed under the terms of the MIT license.