diff options
author | Simon Ser <contact@emersion.fr> | 2019-12-09 16:02:12 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-09 16:05:40 +0100 |
commit | 4f74722c14d18e78e172825961d7a65d25b41d3f (patch) | |
tree | 7ffe867986e26e4b5f4a27cb061030e2337efa96 /template.go | |
parent | a176409933129eccdcf06ef131c76aee497b53aa (diff) | |
download | alps-4f74722c14d18e78e172825961d7a65d25b41d3f.tar.gz alps-4f74722c14d18e78e172825961d7a65d25b41d3f.zip |
Add basic support for plugins
Diffstat (limited to 'template.go')
-rw-r--r-- | template.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/template.go b/template.go index f12e2ec..a4c3ee0 100644 --- a/template.go +++ b/template.go @@ -1,6 +1,7 @@ package koushin import ( + "fmt" "html/template" "io" "net/url" @@ -13,7 +14,16 @@ type tmpl struct { t *template.Template } -func (t *tmpl) Render(w io.Writer, name string, data interface{}, c echo.Context) error { +func (t *tmpl) Render(w io.Writer, name string, data interface{}, ectx echo.Context) error { + // ectx is the raw *echo.context, not our own *context + ctx := ectx.Get("context").(*context) + + for _, plugin := range ctx.server.plugins { + if err := plugin.Render(name, data); err != nil { + return fmt.Errorf("failed to run plugin '%v': %v", plugin.Name(), err) + } + } + return t.t.ExecuteTemplate(w, name, data) } |