Golang Monorepo
This repository is an example monorepo using golang.
Notes:
- Due to the limitations of the go module system, we use a single
go.mod
file at the root level.
- We use
lib
instead of pkg
because the modules under lib
are meant for direction consumption in the services.
Stack
This repository uses go-chi as a router, it uses sqlc for the DAL and PGX as the DB driver
for Postgres.
Setup
pre-commit
We use pre-commit to orchestrate linting.
- install pre-commit on your machine.
- install the pre-commit hooks by executing
pre-commit install
in the repository root.
pre-commit commands
pre-commit autoupdate
to update the hooks
pre-commit run --all-files
to execute against all files
Docker
There is a dockerfile
in the repository root which uses distroless
as the production image. Use docker compose for local development:
docker compose up --build
SQLC
- sqlc.
- run
sqlc generate
or any of the other commands in the root.
Migrations
This project uses goose for database migrations.
- Use the
taskfile
commands to run the database migrations.
- Make sure to have
DATABASE_URL
in your *.env file.
TaskFile
There is a Taskfile.yaml
file, which is a task runner. This project uses go-task for running task, and it's pretty simple to use.
- For installation of
taskfile
use these instructions.
- For running the tasks run:
task <task-name>
, ex: task greet