feat: comprehensive blog example with module-based component layout#5
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5 +/- ##
=======================================
Coverage 96.65% 96.65%
=======================================
Files 13 13
Lines 1197 1197
=======================================
Hits 1157 1157
Misses 26 26
Partials 14 14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Per review on PR #5: ServeHTTP returns error, so handlers should propagate store and parse errors to the framework's error pipeline rather than discarding them with `_`. Touches every admin form action plus the auth session-id generator that Login depends on.
URLFor and components.URL accept any for varargs, so int IDs can be passed
directly. templ also renders integer types in { ... } expressions and
attributes natively. Remove the redundant conversions and the now-unused
fmt/strconv imports they pulled in. Also surface strconv.Atoi error in
postEditPage.Props (was the last `id, _ :=` in a Props that returns error).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
examples/blog/— a full blog (public reader + admin CMS) organized as per-feature Go packages with sharedui/packages, mirroring the layout you'd reach for in a typical React/Next app. Replaces the never-merged single-package attempt in PR #2; please close that one when this lands.Why a new example
None of the existing examples use
WithArgsDI, page-levelMiddlewares(), a custom error handler, deep nested routes, or cross-package component composition. This one does — and demonstrates them in a coherent app rather than a contrived snippet.What it shows
blog/,admin/) + sharedui/layout,ui/components.templRef("loginPage")for cross-feature links to avoid import cyclesui/layout/layout.templ/admin/posts/{id}/edit)admin/routes.go,admin/posts.goWithArgs(store, authSvc)consumed byProps/ServeHTTP/Middlewaresmain.go+ every PropsMiddlewares()returningRequireAdmin(with DI)admin/routes.goProps(r, target RenderTarget, *store.Store)with conditional widget loadsadmin/dashboard.templ,blog/search.templtarget.Is(StatsGrid)thenRenderComponentadmin/dashboard.templ,admin/components.templPage()+Content()split for HTMX#contentswapsblog/home.templ,admin/dashboard.templServeHTTPform handlers — redirect for non-HTMX,RenderComponent(...)partial for HTMXblog/comment.go,admin/posts.goWithErrorHandlerrendering a styled cross-package error component (full doc + HTMX block)main.go+ui/componentsURLForwith path params + query-string templates[]any{p, "?page={page}"}blog/category.templID/IDTargetwiring forhx-targetApp features
Notes for reviewers
admin.LoginPageis mounted as a sibling ofadmin.Pages(not a child) becauseadmin.Pages.Middlewares()returnsRequireAdmin, which would otherwise gate the login form itself./posts/create,/posts/{id}/update,/posts/{id}/delete) instead ofPOST /posts/{id}to avoid Go'sServeMuxconflict with literal segments like/posts/new.Test plan
go vet ./...at repo root — cleantempl generate -include-version=false && go build ./... && go vet ./...inexamples/blog/— cleango test ./...at repo root — framework tests still pass/,/posts/welcome,/categories/guides?page=1,/search?q=propsall 200/posts/nope; HTMXHX-Requestreturns justErrorBlock(301 bytes) vs fullErrorPage(~1KB)/admin/303s to/admin/login; correct creds 303 to/admin/; logout invalidates sessionHX-Target: stats-grid→ 906 bytes (just widget);recent-posts-card→ 1409 bytes;content→ body fragment (3218 bytes); full doc → 4259 bytesCommentsListwith new commentPostsTablepartialHX-Target: search-resultsreturns just the results div