Documentation
¶
Overview ¶
Package tmplcache keeps texts that are no Go code in files of their own, the SQL of a store or a prompt, and hands them out filled in. The files are templates. A program reads and parses all of them once, when it starts, so a text that does not parse stops the start and not a request, and it looks them up by their path afterwards. The package knows nothing of this module: the caller says which files, and what each is filled in with.
Index ¶
Constants ¶
const Suffix = ".gotmpl"
Suffix is what the name of a template file ends with. Preload leaves every other file alone.
Variables ¶
var ( // ErrNoTemplates is returned by Preload for a file system that holds no template. ErrNoTemplates = errors.New("no template files found") // ErrNotFound is returned by Execute for a path that no template has. ErrNotFound = errors.New("template not found") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds the parsed templates of one file system by their path in it. Preload writes it once and nothing changes it afterwards, so any number of goroutines may execute its templates at the same time.
func Preload ¶
Preload reads every file of fsys whose name ends with Suffix, at any depth, and parses them together, each under its path: one template can include another with {{template "user/columns.gotmpl" .}}. funcs are the functions the templates may call; nil means none. A template that names a key its data does not have fails when it is executed, and so does one that includes a template that is not there.