Install Golang and PostgresSQL. We recommend using a version manager like asdf to manage your installations. Use the versions of the tools listed in the .tool-versions
file.
-
(For
asdf
only) if not already installed, install the necessary plugins:asdf plugin add golang asdf plugin add postgres
-
Install the required versions of the tools:
asdf install golang 1.21.5 asdf install postgres 14.8
To work with and debug the API, we also strongly recommend installing tools like Postman.
We use pre-commit and pre-push hooks to ensure that code is formatted and linted before committing and pushing. To set up the hooks, run the following commands:
make hooks
Notes:
- Hooks only work on macOS/Linux. Support for Windows is coming soon.
- You will need to install golangci-lint locally for git hooks to work. See Running linter for instructions.
Run the following command to create the database:
make db_create
For this step onwards, make sure you have your environment variables set up correctly. See Setting up environment variables for more details.
Run the migration target to migrate the database:
make db_migrate
By default, the migration target will run all pending migrations (visible using make db_status
command). To only run a certain number of migrations forward, use the steps
argument:
make db_migrate steps=1
To roll back the most recent migration, run the following command:
make db_rollback
To roll back a certain number of migrations, use the steps
argument:
make db_rollback steps=1
Copy .env.example
to .env
and fill in/modify the required values as needed.
make dev
Step 1: Install golangci-lint locally.
Step 2: Run the lint commmand:
make lint
By convention, test files are named *_test.go
and are placed in the same directory as the code they are testing.
To run all tests:
make test
To run all tests and view test coverage:
make coverage
make build