A simple opinionated Go web app template
Find a file
Leo 43219268e9 feat: Add Sliding expiration for user_sessions
The user_session is valid for 24 hours, but the session will be bumped if it has been over an hour since the last update. An hour was set as a deadline, so that we would not update the user_session rows too often.
2026-08-17 23:47:11 +03:00
cmd feat: Add Sliding expiration for user_sessions 2026-08-17 23:47:11 +03:00
internal feat: Add Sliding expiration for user_sessions 2026-08-17 23:47:11 +03:00
migrations feat: Add Sliding expiration for user_sessions 2026-08-17 23:47:11 +03:00
scripts Initial commit 2026-08-15 23:57:52 +03:00
ui Add Homepage, login, signup page UI. Add logout functionality 2026-08-17 15:42:27 +03:00
.air.toml Initial commit 2026-08-15 23:57:52 +03:00
.env.example Initial commit 2026-08-15 23:57:52 +03:00
.gitignore Initial commit 2026-08-15 23:57:52 +03:00
go.mod Initial commit 2026-08-15 23:57:52 +03:00
go.sum Initial commit 2026-08-15 23:57:52 +03:00
README.md feat: Add Sliding expiration for user_sessions 2026-08-17 23:47:11 +03:00
sqlc.yaml Initial commit 2026-08-15 23:57:52 +03:00
todo.txt feat: Add Sliding expiration for user_sessions 2026-08-17 23:47:11 +03:00

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 migrationns
  • sqlc for generating typed SQL queries
  • air for live reload (optional)
    go install github.com/pressly/goose/v3/cmd/goose@latest
    go install github.com/air-verse/air@latest
    

Setup

  1. Copy environment variables:

    cp .env.example .env
    
  2. Update .env with your database credentials (both the DB_* and GOOSE_* values).

  3. Install dependencies:

    go mod tidy
    
  4. Run database migrations:

    ./scripts/goose.sh up
    
  5. 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 login
  • GET /user - Get user info (requires session cookie)

Database Schema

  • user_auth - User accounts with Argon2 password hashes
  • user_session - User sessions with SHA-256 hashed token secrets