No description
  • Go 66.8%
  • templ 17.2%
  • CSS 14.6%
  • Makefile 1.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-24 11:57:58 +00:00
cmd/server Scaffold Go web server with pgx, PostgreSQL, and templ 2026-10-23 17:31:32 +00:00
internal Add store products and price positions with latest price page 2026-10-24 11:57:58 +00:00
.env.example Scaffold Go web server with pgx, PostgreSQL, and templ 2026-10-23 17:31:32 +00:00
.gitignore Scaffold Go web server with pgx, PostgreSQL, and templ 2026-10-23 17:31:32 +00:00
go.mod Scaffold Go web server with pgx, PostgreSQL, and templ 2026-10-23 17:31:32 +00:00
go.sum Scaffold Go web server with pgx, PostgreSQL, and templ 2026-10-23 17:31:32 +00:00
Makefile Scaffold Go web server with pgx, PostgreSQL, and templ 2026-10-23 17:31:32 +00:00
README.md Add store products and price positions with latest price page 2026-10-24 11:57:58 +00:00

Products

A small Go web application scaffold using:

  • Go standard library HTTP server (net/http with the Go 1.22+ route patterns)
  • PostgreSQL with the pgx v5 driver and pgxpool
  • templ for type-safe HTML templates
  • Embedded, automatically applied SQL migrations

It ships with a product catalog: a home page, a product list, and a form to add products. Store listings (store_products) and their price history (positions) are also stored; /store-products shows every listing with its latest recorded price.

Requirements

  • Go 1.26+
  • PostgreSQL running locally

Setup

  1. Create the database and role (adjust credentials as you like):

    CREATE ROLE products WITH LOGIN PASSWORD 'products';
    CREATE DATABASE products OWNER products;
    
  2. Configure the application:

    cp .env.example .env
    

    DATABASE_URL defaults to postgres://products:products@localhost:5432/products?sslmode=disable if it is not set. Real environment variables take precedence over .env.

  3. Run the server:

    make run
    

    Open http://localhost:8080. Migrations and seed data are applied on startup.

Commands

Command Description
make run Generate templates and start the server
make build Build a static binary at bin/server
make test Generate templates and run tests
make templ Regenerate *_templ.go files
make tidy Run go mod tidy

Layout

cmd/server/              Application entrypoint and graceful shutdown
internal/config/         Environment-based configuration
internal/database/       pgx pool setup and embedded SQL migrations
internal/store/          Data access (products, store products, positions)
internal/view/           templ components + generated Go code
internal/web/            Routes, handlers, middleware, static assets

Environment variables

Variable Default
ADDR :8080
DATABASE_URL postgres://products:products@localhost:5432/products?sslmode=disable

Notes

  • Templates are compiled to Go code. Commit the generated *_templ.go files so go build works without the templ CLI; regenerate them after editing .templ files. The templ CLI is pinned as a tool dependency in go.mod (Go 1.24+ tool directive) and runs via go tool templ or make templ.
  • Migrations live in internal/database/migrations and are embedded into the binary. They run exactly once and are tracked in schema_migrations.
  • GET /healthz checks database connectivity.