refactor RenderTemplate a bit
This commit is contained in:
parent
21ccdebd7a
commit
9a42079ae3
|
@ -82,20 +82,16 @@ func GenerateNewTemplateCache() (models.TemplateCache, error) {
|
||||||
|
|
||||||
// RenderTemplate renders requested template (t), pulling from cache.
|
// RenderTemplate renders requested template (t), pulling from cache.
|
||||||
func RenderTemplate(w http.ResponseWriter, filename string, data *models.TemplateData) {
|
func RenderTemplate(w http.ResponseWriter, filename string, data *models.TemplateData) {
|
||||||
var cache models.TemplateCache
|
if !app.UseCache {
|
||||||
if app.UseCache {
|
c, err := GenerateNewTemplateCache()
|
||||||
cache = app.TemplateCache
|
|
||||||
} else {
|
|
||||||
var err error
|
|
||||||
cache, err = GenerateNewTemplateCache()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Logger.Fatal("Error generating template cache, bailing out!")
|
app.Logger.Fatal("Error generating template cache, bailing out!")
|
||||||
}
|
}
|
||||||
app.TemplateCache = cache
|
app.TemplateCache = c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get templates from cache
|
// Get templates from cache
|
||||||
template, ok := cache.Cache[filename]
|
template, ok := app.TemplateCache.Cache[filename]
|
||||||
if !ok {
|
if !ok {
|
||||||
app.Logger.Fatal(fmt.Sprintf("Couldn't get %s from template cache, bailing out!", filename))
|
app.Logger.Fatal(fmt.Sprintf("Couldn't get %s from template cache, bailing out!", filename))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue