A simple opinionated Go web app template
| cmd | ||
| internal | ||
| migrations | ||
| scripts | ||
| .air.toml | ||
| .env.example | ||
| .gitignore | ||
| go.mod | ||
| go.sum | ||
| README.md | ||
| sqlc.yaml | ||
Go Backend Template
A simple Go backend with authentication using native net/http and PostgreSQL.
Features
- Session-based authentication
- Argon2 password hashing
- PostgreSQL database
- CORS support
- Request logging middleware
- Native Go HTTP server (no external frameworks)
Requirements
- Go 1.24+
- PostgreSQL
- goose for migrations, air for live reload (optional):
go install github.com/pressly/goose/v3/cmd/goose@latest go install github.com/air-verse/air@latest
Setup
-
Copy environment variables:
cp .env.example .env -
Update
.envwith your database credentials (both theDB_*andGOOSE_*values). -
Install dependencies:
go mod tidy -
Run database migrations:
./scripts/goose.sh up -
Run the server:
air # live reload, or: go run ./cmd
Migrations
goose.sh loads .env and passes through to goose (up, down, status, ...).
Create a new migration with:
./scripts/goose-create.sh add_widgets
SQLC (optional)
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/.
API Endpoints
POST /login- User loginGET /user- Get user info (requires session cookie)
Database Schema
user_auth- User accounts with Argon2 password hashesuser_session- User sessions with SHA-256 hashed token secrets