You can set up templates with ztpl.Init()
, which can then be reloaded from
the filesystem with ztpl.Reload()
, e.g. with github.com/teamwork/reload:
ztpl.Init("tpl", pack.Templates)
go func() {
err := reload.Do(zlog.Module("main").Debugf, reload.Dir("./tpl", ztpl.Reload))
if err != nil {
panic(errors.Errorf("reload.Do: %v", err))
}
}()
Simple replacing a templates
variable introduces race conditions, this takes
care of that.
This also automatically runs either text/template
or html/template
depending on the file extension (.gotxt
or .gohtml
).