An opinionated Go project template for scraper, bot, and service workloads. Batteries included: a TLS-fingerprinted HTTP client via fphttp, exponential backoff, bounded concurrency, file-backed state, PostgreSQL, and structured logging.
Install gonew:
go install golang.org/x/tools/cmd/gonew@latestScaffold a new project:
gonew github.com/aarock1234/go-template@latest github.com/you/myprojectClones the template and rewrites all import paths to your module name.
After cloning, run the setup script to configure optional features:
make setupPrerequisites: Go 1.26+, Docker, goose, sqlc
- Replace
pkg/templatewith your own domain logic - Update
cmd/template/main.goto wire your services - Add SQL queries to
pkg/db/queries/and runmake generate - Copy and configure your environment:
cp .env.example .envLocally:
make devOr with Docker:
make upgo-template/
├── cmd/template/ entrypoint
├── pkg/
│ ├── client/ HTTP client via fphttp (TLS/HTTP2 fingerprinting, proxy, cookies)
│ ├── cycle/ thread-safe round-robin file-backed line cycling
│ ├── db/ PostgreSQL pool, sqlc queries, transactions, advisory locks
│ ├── env/ .env loader and struct-tag validation
│ ├── log/ structured slog with tint and context injection
│ ├── ptr/ generic pointer helpers
│ ├── retry/ exponential backoff with jitter
│ ├── state/ file-backed JSON persistence with file locking
│ ├── template/ skeleton domain service (replace this)
│ └── worker/ bounded-concurrency primitives via errgroup
├── Dockerfile multi-stage: dev, builder, production (Alpine)
├── compose.yaml dev mode with docker compose watch
└── Makefile
| Command | Description |
|---|---|
make dev |
Run the application |
make build |
Compile binary to bin/template |
make test |
Run tests with race detector via go test -race |
make lint |
Static analysis via go vet |
make fix |
Modernize code via go fix |
make format |
Format code via go fmt |
make generate |
Run code generation via sqlc generate |
| Command | Description |
|---|---|
make db |
Start postgres only (localhost:5432) |
make db-down |
Stop postgres |
make migrate |
Run migrations up |
make migrate-down |
Roll back last migration |
make migrate-new |
Create a new migration file |
The postgres service is opt-in. make db starts it locally on localhost:5432. To use an external database instead, skip make db and set DATABASE_URL in .env to point at your instance.
| Command | Description |
|---|---|
make up |
Start full stack (app + postgres) |
make down |
Stop all services |
make watch |
Hot reload via docker compose watch |
A manual GitHub Actions workflow is provided for releases:
- Open Actions -> Release
- Click Run workflow
- Either:
- enter an explicit version such as
v1.2.3, or - leave
versionempty and choose apatch,minor, ormajorbump
- enter an explicit version such as
- Optionally choose a ref and whether the release is a prerelease
The workflow resolves the final version, validates it, runs go vet and go test -race, pushes the git tag, and creates a GitHub Release with autogenerated notes.
Automatic increment uses the highest existing stable semver tag matching v<major>.<minor>.<patch>. If no tags exist yet, the first auto-incremented release starts from v0.0.1.
Configured via environment variables. Copy .env.example to .env to get started.
The HTTP client verifies TLS certificates by default. If you need scraper-style insecure TLS for a specific target, enable it explicitly with client.WithInsecureSkipVerify(true).
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL |
Yes | none | PostgreSQL connection string |
LOG_LEVEL |
No | info |
debug, info, warn, error |