An opinionated DIY template for Golang JSON API applications
- Router (chi)
- Real IP middleware (chi)
- Request ID middleware
- Error recovery middleware
- CORS middleware (chi)
- Compatibility with standard library (net/http) middleware
- Error handling
- Secure Configurable Authentication (based on Refresh Tokens)
- Transactional Emails via Scaleway
- CAPTCHA via Cloudflare Turnstile
- Background jobs processing setup via Asynq
- Testing setup (ginkgo)
- Github Actions Test job
- Github Actions Lint job (golangci-lint)
- Docker Compose setup for development
- Multi-stage Dockerfile
- Hot-reload via Air
./setup-dev.shgo mod downloaddocker compose up postgres redisThe second part of the command is a workaround until dbmate image supports
postgres version 18
docker compose run --rm dbmate migrate && docker compose run --rm dump_schemadocker compose run --rm psql --echo-all --file /db/seed.sqlair -c ./.air.server.toml
# Or (without hot reload)
go run -tags=debug cmd/server/main.go# Drop the database
docker compose run --rm dbmate drop
# Create the database and run migrations
docker compose run --rm dbmate upMake sure that steps 1-4 from Running the app locally are completed
air -c ./.air.worker.toml
# Or (without hot reload)
go run -tags=debug cmd/worker/main.goMake sure that steps 1-4 from Running the app locally are completed
air -c ./.air.scheduler.toml
# Or (without hot reload)
go run -tags=debug cmd/scheduler/main.godocker compose run --build --rm testdocker compose run --build --rm lintServer, worker and scheduler binaries will be in the same image
docker build . --tag go-api-template:latest