Skip to main content

structpages

Struct-based routing for Go web apps.

Built on http.ServeMux. First-class Templ and HTMX. Type-safe URLs.

Alpha — APIs may change

Struct-based routing

Define routes as Go struct fields with tags. Nesting structs creates nested route hierarchies. No magic registration calls.

Templ + HTMX

First-class Templ support. HTMX-aware partial rendering via the default HTMXRenderTarget — return the right component for hx-target without manual dispatch.

Type-safe URLs

URLFor generates URLs from struct references, ID/IDTarget generates matching HTML ids and CSS selectors. The structpages-lint analyzer catches mismatches at build time.

Quick look

package main

import (
"log"
"net/http"
"github.com/jackielii/structpages"
)

type index struct {
product `route:"/product Product"`
team `route:"/team Team"`
contact `route:"/contact Contact"`
}

templ (index) Page() {
<html>
<body>
<h1>Welcome</h1>
</body>
</html>
}

func main() {
mux := http.NewServeMux()
if _, err := structpages.Mount(mux, index{}, "/", "Home"); err != nil {
log.Fatal(err)
}
log.Println("Listening on :8080")
http.ListenAndServe(":8080", mux)
}

See the full walkthrough →