refactor: template renderer cleanup
This commit is contained in:
parent
c05b34f4cd
commit
b3b56754c2
1 changed files with 18 additions and 9 deletions
|
@ -1,3 +1,10 @@
|
|||
// Template rendering
|
||||
//
|
||||
// Abstracts the rendering of static HTML templates.
|
||||
// Render(...) handles rendering the provided template with the
|
||||
// default partial templates (header, footer, general base...), handles
|
||||
// getting the paths to those template files and feeding the data (including
|
||||
// some internally-generated context) when hydrating the template.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -8,6 +15,15 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type RenderMeta struct {
|
||||
RenderStart time.Time
|
||||
}
|
||||
|
||||
type RenderContext struct {
|
||||
Data interface{}
|
||||
Meta RenderMeta
|
||||
}
|
||||
|
||||
func getRenderDuration(start time.Time) time.Duration {
|
||||
return time.Now().Sub(start)
|
||||
}
|
||||
|
@ -35,14 +51,7 @@ func Render(w io.Writer, templateName string, data interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
type RenderMeta struct {
|
||||
RenderStart time.Time
|
||||
}
|
||||
renderContext := RenderContext{Data: data, Meta: RenderMeta{RenderStart: start}}
|
||||
|
||||
type RenderContext struct {
|
||||
Data interface{}
|
||||
Meta RenderMeta
|
||||
}
|
||||
|
||||
return tmpl.ExecuteTemplate(w, "base", RenderContext{Data: data, Meta: RenderMeta{RenderStart: start}})
|
||||
return tmpl.ExecuteTemplate(w, "base", renderContext)
|
||||
}
|
Loading…
Reference in a new issue