From 8ddd95e3614718b5ff335fe484c451ca45b9a345 Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Wed, 12 Oct 2016 01:26:39 -0500 Subject: [PATCH] tpl: Factor out double Lookup in executeTemplate --- tpl/template.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tpl/template.go b/tpl/template.go index 479298976..431ea5a24 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -117,19 +117,17 @@ func partial(name string, contextList ...interface{}) template.HTML { } func executeTemplate(context interface{}, w io.Writer, layouts ...string) { - worked := false + var worked bool for _, layout := range layouts { - - name := layout - - if Lookup(name) == nil { - name = layout + ".html" + templ := Lookup(layout) + if templ == nil { + layout += ".html" + templ = Lookup(layout) } - if templ := Lookup(name); templ != nil { - err := templ.Execute(w, context) - if err != nil { - jww.ERROR.Println(err, "in", name) + if templ != nil { + if err := templ.Execute(w, context); err != nil { + jww.ERROR.Println(err, "in", layout) } worked = true break