# Go Backend Template A simple opinionated Go web app template. The intention for this project is to work as a template, where the developer should be able to concentrate right away on the business problem and not the usual dev environment and auth wiring. The focus is intentionally on mainly functionality, so the UI is bare-bones. ## Features - Session-based authentication with a sliding expiration - Argon2 password hashing - PostgreSQL database - CORS support - Request logging middleware - Native Go HTTP server (no external frameworks) - HTMX for interactivity ## Requirements - [Go](https://go.dev) 1.24+ - PostgreSQL - [goose](https://github.com/pressly/goose) for migrations - [sqlc](https://github.com/sqlc-dev/sqlc) for generating type-safe queries from SQL - [air](https://github.com/air-verse/air) for live reload (optional) ```bash go install github.com/pressly/goose/v3/cmd/goose@latest go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest go install github.com/air-verse/air@latest ``` ## Setup 1. Copy environment variables: ```bash cp .env.example .env ``` 2. Update `.env` with your database credentials (both the `DB_*` and `GOOSE_*` values). 3. Install dependencies: ```bash go mod tidy ``` 4. Run database migrations: ```bash ./scripts/goose.sh up ``` 5. Run the server: ```bash air # live reload, or: go run ./cmd ``` 6. Enable the repo's git hooks (rejects commits with unformatted Go files): ```bash git config core.hooksPath .githooks ``` ## Migrations `goose.sh` loads `.env` and passes through to goose (`up`, `down`, `status`, ...). Create a new migration with: ```bash ./scripts/goose-create.sh add_widgets ``` ## SQLC Query codegen is configured in `sqlc.yaml` (engine `postgresql`, schema read from `migrations/`). Add `.sql` files under `internal/database/queries/` and run `sqlc generate` to emit typed accessors into `internal/database/sqlc/`. ## Database Schema - `user_auth` - User accounts with Argon2 password hashes - `user_session` - User sessions with SHA-256 hashed token secrets