Build with html/template power tools: http.Handler generation and static type-checking of *.gohtml files.
{{define "GET /article/{id} GetArticle(ctx, id)"}}
<h1>{{.Result.Title}}</h1>
{{end}}func (s Server) GetArticle(ctx context.Context, id int) (Article, error) { ... }The template name is the route, the handler call, and the parameter list. Muxt reads it, parses the request into those arguments, calls your method, and renders the result.
You can stay in hypermedia-land and drive a significant amount of behavior from your template source files.
Muxt plays super well with fixi, htmx, Datastar, and plain server-rendered HTML.
go install github.com/typelate/muxt@latestOr as a project tool: go get -tool github.com/typelate/muxt. Pre-built binaries are also attached to each release.
This is what muxt uses to map Go <-> HTML.
Standard http.ServeMux pattern, optionally with a status code and method call:
[METHOD ][HOST]/[PATH][ HTTP_STATUS][ CALL]
Example: "POST /user/{id} 201 CreateUser(ctx, id, form)"
Supported parameters: ctx, request, response, path params, form (URL-encoded body), multipart (file uploads, including *multipart.FileHeader fields). Returns and errors flow through TemplateData[R, T]. Status codes can come from the template name, return values, or error types.
TemplateRoutePaths extends type safety to URLs: {{$.Path.GetArticle 42}} instead of hardcoded href="/article/42". Change the route pattern, the compiler finds every stale reference.
- Local example: complete application with tests (pkg.go.dev)
- Sortable Example: HTMX-enabled table row sorting
- HTMX Template: full HTMX integration patterns
The command tests double as readable examples of every feature.
muxt generate: generatehttp.Handlerglue (writestemplate_routes.go)muxt check: type-check templates without generating (use in CI or editor save hooks)muxt list-template-calls/muxt list-template-callers: explore call sites and callers
- Quick Start: your first Muxt server
- Reference: CLI, syntax, parameters, type checking
- Explanation: design philosophy, patterns, decisions
See the full documentation index.
- html/template: template syntax, functions, escaping
- net/http:
ServeMuxrouting patterns,Handlerinterface - embed: file embedding directives
- Routing Enhancements for Go 1.22: pattern syntax Muxt extends
Muxt generator: GNU AGPLv3
Generated code: not covered by AGPL. Muxt asserts no copyright over its output. Treat generated files as your own code, under whatever license your project uses.
No warranty. Muxt and its generated output are provided "as is", without warranty of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, and non-infringement. You are responsible for reviewing, testing, and securing any code generated by Muxt before using it. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability arising from the use of Muxt or its output.