You must need to install some dependencies before start this project. These dependencies are:
- Go version 1.21 or greater; 🔗 https://go.dev/dl/
- Docker and Docker Compose; 🔗 https://docs.docker.com/compose/install/
To install the golang dependencies you must run:
make install
To set the environment variables you only need to create a file .env
based on .env.example
and update the variables when necessary.
To have database
, cache
and jaeger
on your local machine you only need to run:
make local-up
To run the migrations you can run:
make mig-up
and to get the api running you can run:
make run
# or
make run-watch
Ps.: run-watch will watch the files changes and restart the API when it was necessary.
To access the swagger you can just run:
make open-swagger
or just access: http://localhost:8080/swagger/index.html
When you create a new endpoint, we need to run this command to update the swagger docs:
make docs
🔗 Here you can see more details about the library this project is using to generate this docs based on comments.
To access the jaeger you can just run:
make open-jaeger
or just access: http://localhost:16686/search
Migrations is responsible for versionate the database and you can see all migrations that we had until now on the migrations folder.
To run the migrations you can run:
make mig-up
This will run the migrations that your database don't have yet.
If something goes wrong and you need to make a rollback on the last migration, you can run:
make mig-down
Do you want to create a new database change? So you only need to run:
make mig-create MIG_NAME=migration_name
where you must update the migration_name
with something that represents your change. One file is going to be created in the migrations folder and you'll need to put the query that you want and the rollback query.
To know more about how to write your migration, you can go to goose docs.
To run the pipeline test we have two commands:
make test
This command runs the whole pipeline.
The second one runs the pipeline too, but it also shows on a browser the details and where is the uncoverage code is. The command to do this is:
make test-cover
To mock a package or file this project is using the go:generate
+ gomock
and you can do it only including in the first line of the go file the comment:
//go:generate mockgen -source file_name.go -destination mocks/cache_mock.go -package mocks
Ps.: Don't forget to update file_name.go to the right filename.
After that, you only need to run:
make mock
and if you invert the dependency currectly Gomock will create a folder with the mocks that you need.