HTML templates - recommendations to unset ?

103 views
Skip to first unread message

Marc Coquand

unread,
Oct 28, 2024, 8:47:38 AMOct 28
to golan...@googlegroups.com

Hey!

Currently I use gin as my framework and write my HTML markup together
with go templates.

It happens every so often that I miss to set variables, and so I was
wondering if there are any best practices or tooling to help you make
sure that all variables are set?

Thanks,
Marc

Nico Braun

unread,
Oct 28, 2024, 4:15:07 PMOct 28
to golang-nuts
On Monday 28 October 2024 at 13:47:38 UTC+1 Marc Coquand wrote:
> I was wondering if there are any best practices or tooling to help you
> make sure that all variables are set?

You can pass an the "missingkey=error" option to the template. See
https://pkg.go.dev/html/template#Template.Option.

Harmen

unread,
Oct 28, 2024, 11:02:09 PMOct 28
to Marc Coquand, golan...@googlegroups.com
Also check out https://github.com/jba/templatecheck
It allows you to check the templates which otherwise you would only figure out by running them manually.
Reply all
Reply to author
Forward
0 new messages