This guide will help you set up the necessary tools to work on this project. You'll be installing the Go compiler, Docker, Docker Compose, sqlc, and the Go Migrate CLI.
Go to the official Go website and download the installer for your operating system.
- Download the MSI installer from the Go downloads page.
- Run the MSI installer and follow the prompts.
- Download the package file from the Go downloads page.
- Open the package file and follow the instructions to install.
Use the following commands to download and install Go (replace VERSION
with the latest Go version, e.g., 1.20.6
):
wget https://golang.org/dl/goVERSION.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf goVERSION.linux-amd64.tar.gz
Add Go to your PATH by adding the following line to your .bashrc
or .zshrc
file:
export PATH=$PATH:/usr/local/go/bin
Reload your shell configuration:
source ~/.bashrc
# or
source ~/.zshrc
Verify the installation:
go version
Follow the instructions on the Docker website to install Docker for your operating system.
- Download Docker Desktop from the Docker downloads page.
- Run the installer and follow the prompts.
Use the official Docker installation script:
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
Verify the installation:
docker --version
Follow the instructions on the Docker Compose website to install Docker Compose for your operating system.
Docker Compose is included with Docker Desktop.
Run the following commands:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Verify the installation:
docker-compose --version
Follow the instructions on the sqlc website to install sqlc.
brew install sqlc
go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
Verify the installation:
sqlc version
Follow the instructions on the migrate website to install the Go Migrate CLI.
brew install golang-migrate
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
Verify the installation:
migrate -version
The Makefile contains various commands to manage database migrations, run tests, ensure code quality, and build the project. Below are the available targets and their descriptions:
-
help: Display this help message.
make help
-
create-migration: Create a new migration file for a table.
make create-migration table_name=<table_name>
-
migrate-force: Force a migration to a specific version.
make migrate-force version=<version>
-
migrate-up: Migrate the database schema up to the latest version.
make migrate-up
-
migrate-down: Rollback the database schema back
make migrate-down
-
migrate-drop: Drop all database tables.
make migrate-drop
-
migrate-to: Migrate the database schema to a specific version.
make migrate-to version=<version>
-
test: Run all tests with coverage and race detection.
make test
-
tidy: Format code and tidy the mod file.
make tidy
-
audit: Run
go vet
andgolangci-lint
, and verify dependencies.make audit
-
lint: Run
golangci-lint
.make lint
-
lint-fix: Run
golangci-lint
with fix option.make lint-fix
-
sqlc-gen: Generate code using sqlc.
make sqlc-gen
-
docker-compose-up: Build and start Docker Compose services.
make docker-compose-up
-
docker-compose-down: Stop Docker Compose services.
make docker-compose-down
-
build-artifact: Build the project for Linux.
make build-artifact
-
mock: Generate mock implementations for testing.
make mock