Homework — type safety and an /about page
Make it yours.
-
Feel the type safety. In
home.templ, change@Layout("Home")to@Layout(42). Runtempl generate— it won't even generate; you get a Go type error,cannot use 42 (int) as string, at that line. A template bug caught at build time. Fix it back. -
Trigger the stale-template gotcha on purpose. Edit the
<h1>text inhome.templ, reload without runningtempl generate— the old heading is still there. Now runtempl generate, reload — your change appears. Feel the loop: edit → generate → reload. -
Turn your
/aboutroute (from lesson 1) into a real page. Write anAbouttempl component that uses@Layout("About"), and change theAbouthandler torender(w, r, http.StatusOK, web.About()). Now it's a styled page sharing the same header and footer — that's the point of a layout.
Where this is going. Your Home() renders, but it has nothing real to say — the "Skeleton status" card is hardcoded. Lesson 3 connects Postgres: a users table via a goose migration, queried with sqlc, and Home(userCount int64) will show a live count of registered users read from the database. And you'll meet the loveliest fact in the stack — sqlc reads its schema straight from the migrations, so the generated query code can never drift from the real table.