Skip to main content

Introduction

structpages is a Go web framework library that defines routes via struct tags and methods on top of http.ServeMux. It minimises boilerplate for HTML-first apps using Templ and HTMX, and gives you type-safe URL generation and dependency injection without giving up the standard library.

Status

Alpha. APIs may change between minor versions. The library is used in a medium-sized internal project but is not yet battle-tested in production. Pin versions if you adopt it now.

Why structpages

If you've built a Go web app with http.ServeMux, you've written code like:

mux.HandleFunc("GET /products/{id}", handleProductGet)
mux.HandleFunc("POST /products/{id}/comments", handleProductCommentCreate)
mux.HandleFunc("DELETE /products/{id}/comments/{commentID}", handleProductCommentDelete)

That works, but the route structure lives only in string literals. structpages lets you express the same hierarchy as Go structs, so the router and your handler types stay in lockstep:

type product struct {
comments `route:"/comments Comments"`
}

type productPages struct {
product `route:"/products/{id} Product"`
}

Each leaf struct implements a Page() method (typically via Templ), or Props, or ServeHTTP — whichever fits the request shape. URLs are generated by URLFor(&product{}) rather than string concatenation, and the structpages-lint analyzer catches mismatches at build time.

What's next

  • Quick Start — a minimal working example end-to-end.
  • Routing — full route tag syntax and nesting rules.
  • Request Flows — how the dispatcher picks Page / Content / Props / ServeHTTP.