From 9a42079ae3f8c022ebace2379918ffd5eaa75f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Tue, 23 Jan 2024 14:07:16 -0800 Subject: [PATCH] refactor RenderTemplate a bit --- internal/render/render.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/internal/render/render.go b/internal/render/render.go index 40a3b55..37b6b28 100644 --- a/internal/render/render.go +++ b/internal/render/render.go @@ -82,20 +82,16 @@ func GenerateNewTemplateCache() (models.TemplateCache, error) { // RenderTemplate renders requested template (t), pulling from cache. func RenderTemplate(w http.ResponseWriter, filename string, data *models.TemplateData) { - var cache models.TemplateCache - if app.UseCache { - cache = app.TemplateCache - } else { - var err error - cache, err = GenerateNewTemplateCache() + if !app.UseCache { + c, err := GenerateNewTemplateCache() if err != nil { app.Logger.Fatal("Error generating template cache, bailing out!") } - app.TemplateCache = cache + app.TemplateCache = c } // Get templates from cache - template, ok := cache.Cache[filename] + template, ok := app.TemplateCache.Cache[filename] if !ok { app.Logger.Fatal(fmt.Sprintf("Couldn't get %s from template cache, bailing out!", filename)) }