You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am interested in redefinition of templates. Implicit redefinition is disallowed. How about explicit redefinition? Either:
Template.Remove(name string) followed by Template.ParseFiles(names ...string)
Template.Redefine(name, body string) / Template.RedefineFile(name, file string)
Scenario
We have a server which watches a folder for updates. When it receives a write or create for a file, it re-reads in the template. This allows for no-downtime updates to our templates, which is something we value greatly. It also allows for a more streamlined development process (developer isn't spending time restarting the server locally on changes).
With each filesystem event, we receive the event type and the file it affects. We would like to be able to redefine this template at runtime as these events are triggered.
Currently...
// Template has been changes on the filesystem.// Re-read and parse. Store the latest.// Always throws the 'redefinition' error._, err:=rootTmpl.ParseFiles(event.FileName)
iferr!=nil {
log.Printf("error reading template '%s': %v", event.FileName, err)
}
Unfortunately, this fails every time, with template: redefinition of template %NAME%.
Proposal
My proposal is to allow an explicit removal or redefinition. An example with Template.Remove(name string)...
// Allow explicit removal of a template to allow redefinition.err:=rootTmpl.Remove(event.FileName)
iferr!=nil&&err!=template.ErrorNoSuchTemplate {
log.Printf("error removing template '%s': %v", event.FileName, err)
}
// This should NOT return an error._, err=rootTmpl.ParseFiles(event.FileName)
iferr!=nil {
log.Printf("error reading template '%s': %v", event.FileName, err)
}
Current Work-Around
To get around this, we bind to SIGUSR1 and re-read all the templates (Template.ParseFilesGlob), blocking requests until it's re-defined.
The text was updated successfully, but these errors were encountered:
This is already doable without too much trouble by synchronously reparsing the full set of templates when one changes. Plus, removing a template like this will violate invariants maintained by html/template, which escapes the content based on a statically knowable set of templates.
Hey Go team,
I am interested in redefinition of templates. Implicit redefinition is disallowed. How about explicit redefinition? Either:
Template.Remove(name string)
followed byTemplate.ParseFiles(names ...string)
Template.Redefine(name, body string)
/Template.RedefineFile(name, file string)
Scenario
We have a server which watches a folder for updates. When it receives a write or create for a file, it re-reads in the template. This allows for no-downtime updates to our templates, which is something we value greatly. It also allows for a more streamlined development process (developer isn't spending time restarting the server locally on changes).
With each filesystem event, we receive the event type and the file it affects. We would like to be able to redefine this template at runtime as these events are triggered.
Currently...
Unfortunately, this fails every time, with
template: redefinition of template %NAME%
.Proposal
My proposal is to allow an explicit removal or redefinition. An example with
Template.Remove(name string)
...Current Work-Around
To get around this, we bind to
SIGUSR1
and re-read all the templates (Template.ParseFilesGlob
), blocking requests until it's re-defined.The text was updated successfully, but these errors were encountered: