Documentation
¶
Overview ¶
Package templatereloader provides a jaws.TemplateLookuper that reparses templates from disk while running in debug or race builds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a jaws.TemplateLookuper.
If deadlock.Debug is false, it calls template.New("").ParseFS(fsys, fpath).
If deadlock.Debug is true, fsys is ignored and it returns a TemplateReloader that loads the templates using ParseGlob(relpath/fpath).
Types ¶
type TemplateReloader ¶
type TemplateReloader struct {
// Path is the file path templates are loaded from. It is set once by [New]
// and is read-only afterwards: it is read under mu during a reload, so
// mutating it after construction would race with [TemplateReloader.Lookup].
Path string
// contains filtered or unexported fields
}
TemplateReloader reloads and reparses templates if more than one second has passed since the last TemplateReloader.Lookup.
func (*TemplateReloader) LastError ¶ added in v0.500.0
func (tr *TemplateReloader) LastError() (err error)
LastError returns the last reload parse error, or nil after a successful reload.
It is safe to call on a nil *TemplateReloader.
func (*TemplateReloader) Lookup ¶
func (tr *TemplateReloader) Lookup(name string) *template.Template
Lookup returns the named template, reparsing the templates from disk first when more than one second has passed since the last reload.
If a reload fails to parse (for example while a template file is being edited), the last successfully parsed templates are retained and used, so a transient parse error does not take down a running server. Lookup never panics on a reload error.