This section assumes your terminal's current working directory is the project's directory.
Required tools:
- python
- pip
- Install
golangci-lint - Install
pre-commit
pip install pre-commit && pre-commit install
- Install
docker - Install
docker-compose
Tip: Install the Go Linter plugin for GoLand/VSCode
To start the database:
docker-compose up -d
To stop the database:
docker-compose down
To run the server:
go run .
To modify the database's schema, you should create a migration in the migrations package.
Do not delete or modify existing migrations in migrations.go, only add more migrations to it with an increasing
id.
Don't create gin routes with "pure" gin route handlers (functions with the signature func(*gin.Context)), instead
use the createRouteHandler method, which will be able to provide your handler with a database connection and
automatic error handling.
Don't use globals. Ever. They make it harder to test the code. Instead, use depencency injection.
In a nutshell, dependency injection basically means receiving all of a method's dependencies (e.g. database connections
like *gorm.DB) as parameters. This way the caller of the function has to provide it with its dependencies and testing
the function later on is easier, we just have to pass it mocked or real dependencies as parameters, no need to fiddle
around with singletons and globals and whatnot.
Use DTOs (Data Transfer Objects) to send and receive data on routes. DTOs are basically just plain structs with
fields and field tags for validation (take a look at NewUserDto).