This repo is just me messing around with project structure, organization and approaches.
- Go Version 1.21
- Multiple entry points (cmd):
api
Servicemigrations
Serviceseed
Servicestub
(to run locally such as a script, reusing code)
- Shared
internal
modules - Dependency Injection (uber-go/dig)
- Logger (slog)
- Live Reload (cosmtrek/air) (TODO: not yet inside container)
- Makefile
- Semi-automatic Database Transaction handling
For list of dependencies, check go.mod.
I have commited .env
and keys
just to simplify the demonstration. They should NOT be commited in your real project.
To run the project, you have to do the following:
- Run compose
- Run migrations
- Run seed (optional)
docker compose up --build
To run migrations, you have 3 options. Pick one of them:
- Hit F5 (run on vscode)
- Select
migration
and press enter
go run ./cmd/migration
make migration-up
To seed the database:
- Hit F5
- Select
seed
and press enter
(You can also run it manually go run ./cmd/seed
)
Launch localhost to see if it works.
Data won't persist between database executions (missing volume, so if the database container dies, the data will be lost).
You can launch an HTTP Client and make the following request to login:
curl --request POST \
--url http://localhost:8080/auth \
--header 'Content-Type: application/json' \
--data '{
"email": "admin@example.com",
"password": "admin123"
}'
Check at LICENSE.