
Templ Layouts Slots and Component Composition in Go
Build nested templ layouts with children, component slots, optional slots, conditional attributes, a script emitted once and data from the context.
Servers, handlers, middleware, templates, cookies and sessions on net/http, plus the parts of a real website the tutorials leave out.

Build nested templ layouts with children, component slots, optional slots, conditional attributes, a script emitted once and data from the context.

Call handlers directly with httptest.NewRecorder and NewRequest, set path values by hand, fake the store behind them, and assert on status, headers and JSON.

Where templ escapes for you and where it does not: URLs, SafeURL, style strings, Raw, script data and event handlers, shown with real output and tests.

Serve large files from Go with http.ServeContent so browsers can resume downloads and seek in video, and see exactly what each Range header gets back.

Build a webhook receiver in Go that checks an HMAC signature on the raw body, rejects stale and replayed events, answers fast and processes in the background.

Replace the plain text 404 and 405 responses of http.ServeMux with your own pages or JSON, using a catch-all route and a small response wrapper.

Fix listen tcp bind address already in use in a Go server: find the process holding the port, handle containers and restarts, and use port 0 in tests.

Build a typed Go client for a JSON API: context on every call, one generic request helper, an APIError you can test with errors.Is, and paging as an iterator.

Compare templ and html/template on the same 100 row page: render speed and allocations, error timing, escaping, tooling and when each is the right choice.

Give HTTP handlers their database, logger and clients through struct fields or closures, wire everything in main, test with fakes and avoid globals.

Build an HTTP load balancer in Go with round robin and least connections, active health checks with rise and fall thresholds, and passive failure marking.

Add full-text search to a Go site with SQLite FTS5: stemming, bm25 ranking, highlighted snippets, search as you type and safe handling of raw user queries.
We send one email when a new article is published. No spam.