No description
- Go 66.8%
- templ 17.2%
- CSS 14.6%
- Makefile 1.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| cmd/server | ||
| internal | ||
| .env.example | ||
| .gitignore | ||
| go.mod | ||
| go.sum | ||
| Makefile | ||
| README.md | ||
Products
A small Go web application scaffold using:
- Go standard library HTTP server (
net/httpwith 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
-
Create the database and role (adjust credentials as you like):
CREATE ROLE products WITH LOGIN PASSWORD 'products'; CREATE DATABASE products OWNER products; -
Configure the application:
cp .env.example .envDATABASE_URLdefaults topostgres://products:products@localhost:5432/products?sslmode=disableif it is not set. Real environment variables take precedence over.env. -
Run the server:
make runOpen 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.gofiles sogo buildworks without the templ CLI; regenerate them after editing.templfiles. The templ CLI is pinned as a tool dependency ingo.mod(Go 1.24+ tool directive) and runs viago tool templormake templ. - Migrations live in
internal/database/migrationsand are embedded into the binary. They run exactly once and are tracked inschema_migrations. GET /healthzchecks database connectivity.