Muxt is a Go code generator that helps you build server-side rendered web apps with minimal overhead, leveraging Go
1.22’s improved http.ServeMux
and standard html/template
features.
No extra runtime dependencies are required—just plain Go code.
- It allows you to register HTTP routes from HTML templates
- It generates handler functions and registers them on an
*http.ServeMux
- It generates code in handler functions to parse path parameters and form fields
- It generates a receiver interface to represent the boundary between your app code and HTTP/HTML
- Use this to mock out your server and test the view layer of your application
package main
type Server struct{}
func (s Server) F(x int) int { return x * x }
{{define "GET /f/{x} F(x)" -}}
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'/>
<title>Hello, MUXT!</title>
</head>
<body>
<h1>F(x) is {{.Result}}</h1>
<p>x is {{.Request.PathValue "x"}}</p>
</body>
</html>
{{- end}}
The request GET /f/4
will result in a handler that returns:
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'/>
<title>Hello, MUXT!</title>
</head>
<body>
<h1>F(x) is 16</h1>
<p>x is 4</p>
</body>
</html>
For a small runnable example, see: ./example/hypertext/index.gohtml
For larger complete examples, see: