In this exercise, I built a Golang service that gathers new delegations made on the Tezos protocol and exposes them through a public API.
- Go (version 1.22 or later)
- Docker (for containerization)
- Docker Compose (optional, for managing multi-container Docker applications)
- PostgreSQL (for local development)
- Goose (to run migration)
cmd contains the file main.go, we will define how the server/database/redis runs and start the gRPC and HTTP server if we need it.
internal is composed by several folders. It's the core of the microservice.
Like his name, this folder contain all the config that the microservice need.
The database folder contain all the migrations and the postgres logics.
I define all the entities I need in this folder.
I define here the http server and all the handlers methods.
It's the service layer, our handlers will call the service methods and the service call directly database methods.
pkg contains all the libraries that we use in the different micro-services. These libraries are non-product ones. It can be anything from a client connecting to our database to a utility function improving the way we handle the errors.
Make sure you have goose installed on your computer
go install github.com/pressly/goose/v3/cmd/goose@latest
docker-compose.yml is already configured but feel free to update environments variables.
make run
Fetch all delegations:
curl -X GET http://localhost:3000/xtz/delegations
Fetch delegations by year:
curl -X GET http://localhost:3000/xtz/delegations?year=2024
Optional parameters:
limit (default 100) offset (default 0)
postgresql://root:[email protected]/app-db?tLSMode=0
make run-tests