A minimal Go template for building HTTP APIs with Connect RPC, PostgreSQL, and Docker. Use this repo as a starting point for new services.
- Go 1.24+ – Application runtime
- Connect RPC – gRPC-compatible HTTP APIs (proto + generated Go)
- PostgreSQL – Database (pgx)
- Buf – Protobuf schema and code generation
- Docker & Compose – Local development and deployment
- Go 1.24.3 or later
- Buf
- Docker and Docker Compose (for containerized runs)
- PostgreSQL (for local runs without Docker)
buf generateSet the database URL and start the server:
export DATABASE_URL="postgres://user:password@localhost:5432/app"
make runThe API listens on http://localhost:8080.
Starts the app and PostgreSQL with hot reload (Air):
docker compose upEnsure the app service has DATABASE_URL set, e.g. in compose.yml:
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/app| Target | Description |
|---|---|
make all |
Build the binary |
make build |
Build the binary |
make run |
Run the app |
make test |
Run tests (no coverage) |
make test:ci |
Run tests with coverage |
make clean |
Remove build artifacts |
Tests use .env.test for DB connection (PGHOST, PGUSER, PGDATABASE, PGPASSWORD).
.
├── main.go # Entrypoint, DB init, server wiring
├── compose.yml # App + Postgres for local dev
├── Containerfile # Multi-stage: builder, development (Air), production
├── buf.yaml # Buf config
├── buf.gen.yaml # Buf codegen (Connect + Go)
├── db/
│ └── schema.sql # Postgres schema (run on init)
├── proto/ # Protobuf definitions
│ └── app/api/v1/
├── pkg/
│ ├── db/ # Postgres pool and helpers
│ ├── gen/ # Generated Connect/Go code (from proto)
│ └── srv/ # HTTP server, Connect handlers, middleware
└── .github/
└── go.yml # CI: build, test, Codecov
- Define your RPCs in
proto/app/api/v1/api.proto. - Run
buf generate. - Implement the generated interface in
pkg/srv/api.go. - Handlers are already registered in
pkg/srv/srv.go.
| Variable | Description |
|---|---|
DATABASE_URL |
Postgres connection URL (required) |
For tests, use .env.test (or equivalent) with PGHOST, PGUSER, PGDATABASE, PGPASSWORD so that make test can connect to the test database.
- Build:
make all - Tests:
make test:ciwith a Postgres service and coverage upload to Codecov (setCODECOV_TOKENin repo secrets)
Use and modify as needed for your project.