Most of the code were simplified to make it easier to understand.
This is a simple application to show how to implement a Hexagonal Architecture using one Driver Adapter, the go-chi
library, and two Driven Adapters, PostgresSQL and MongoDB.
The code can switch between the two databases follwing the ports and adapters concept.
- Docker
- Docker Compose
- Go
- First, run the databases using Docker Compose:
docker-compose up -d
- Then, run the application:
go run cmd/main.go
There are four endpoints available, two for each database connection:
- PostgreSQL:
POST /v1/games
GET /v1/games/{id}
- MongoDB:
POST /v2/games
GET /v2/games/{id}
The POST
endpoints receive a JSON body with the following structure:
{
"title": "Uncharted",
}
And return an ID for the created game.
The GET
endpoints receive an ID as a path parameter from a game created in the corresponding database and return a JSON body with the following structure:
{
"title": "Uncharted",
}