Skip to content

typelate/muxt

Repository files navigation

Muxt Go Reference

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.

Install

go install github.com/typelate/muxt@latest

Or as a project tool: go get -tool github.com/typelate/muxt. Pre-built binaries are also attached to each release.

Template Name Syntax

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.

Examples

The command tests double as readable examples of every feature.

Commands

  • muxt generate: generate http.Handler glue (writes template_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

Documentation

See the full documentation index.

Go Standard Library

License

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.