Check is a Go library for statically type-checking text/template and html/template. It catches template/type mismatches early, making refactoring safer when changing types or templates.
If all your ExecuteTemplate calls use a string literal for the template name and a static type for the data argument, you can use the CLI directly:
go get -tool github.com/typelate/check/cmd/check-templates
go tool check-templates ./...Flags:
-v— list each call with position, template name, and data type-C dir— change working directory before loading packages-o format— output format:tsv(default) orjsonl
Call Execute with a types.Type for the template's data (.) and the template's parse.Tree. See example_test.go for a working example.
muxt— builds on this library to type-check templates wired to HTTP handlers. If you only need command-line checks,muxt checkworks too.- jba/templatecheck — a more mature alternative for template type-checking.
- You must provide a
types.Typefor the template's root context (.). - No support for third-party template packages (e.g. safehtml).
- Cannot detect runtime conditions such as out-of-range indexes or errors from boxed types.