diff options
author | Mike Crute <mike@crute.us> | 2023-10-18 12:44:41 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2023-10-18 12:44:41 -0700 |
commit | 4ba637b3c3596d6fb7d073d70f23e4f421949bdd (patch) | |
tree | 0d29769b9acd79d0c22417536bdc59fc37079d44 | |
parent | 86639f865a9a38ced67eb9d80b915436e0819a77 (diff) | |
download | golib-4ba637b3c3596d6fb7d073d70f23e4f421949bdd.tar.bz2 golib-4ba637b3c3596d6fb7d073d70f23e4f421949bdd.tar.xz golib-4ba637b3c3596d6fb7d073d70f23e4f421949bdd.zip |
echo: allow plugins to hook templates
-rw-r--r-- | echo/echo_default.go | 6 | ||||
-rw-r--r-- | echo/interfaces.go | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/echo/echo_default.go b/echo/echo_default.go index cbe43cb..8440fe2 100644 --- a/echo/echo_default.go +++ b/echo/echo_default.go | |||
@@ -61,6 +61,7 @@ type EchoConfig struct { | |||
61 | TrustedProxyIPRanges []string | 61 | TrustedProxyIPRanges []string |
62 | EmbeddedTemplates fs.FS | 62 | EmbeddedTemplates fs.FS |
63 | DiskTemplates fs.FS | 63 | DiskTemplates fs.FS |
64 | ProvideTemplateStore []WantsTemplateStore | ||
64 | TemplateFunctions template.FuncMap | 65 | TemplateFunctions template.FuncMap |
65 | CombinedHostLogFile string | 66 | CombinedHostLogFile string |
66 | RedirectToWWW bool | 67 | RedirectToWWW bool |
@@ -227,6 +228,11 @@ func (w *EchoWrapper) configureTemplates(c *EchoConfig) error { | |||
227 | templates = c.EmbeddedTemplates | 228 | templates = c.EmbeddedTemplates |
228 | } | 229 | } |
229 | 230 | ||
231 | // Configure plugins that want access to the template store | ||
232 | for _, w := range c.ProvideTemplateStore { | ||
233 | w.ConfigureTemplateStore(templates) | ||
234 | } | ||
235 | |||
230 | // Only install template handlers if the path is set | 236 | // Only install template handlers if the path is set |
231 | if templates != nil { | 237 | if templates != nil { |
232 | tr, err := NewTemplateRenderer(templates, "*.tpl", c.TemplateFunctions, w.Debug) | 238 | tr, err := NewTemplateRenderer(templates, "*.tpl", c.TemplateFunctions, w.Debug) |
diff --git a/echo/interfaces.go b/echo/interfaces.go index f3380c6..1f3957a 100644 --- a/echo/interfaces.go +++ b/echo/interfaces.go | |||
@@ -1,6 +1,8 @@ | |||
1 | package echo | 1 | package echo |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "io/fs" | ||
5 | |||
4 | "github.com/labstack/echo/v4" | 6 | "github.com/labstack/echo/v4" |
5 | ) | 7 | ) |
6 | 8 | ||
@@ -18,3 +20,9 @@ type URLRouter interface { | |||
18 | Group(string, ...echo.MiddlewareFunc) *echo.Group | 20 | Group(string, ...echo.MiddlewareFunc) *echo.Group |
19 | Add(string, string, echo.HandlerFunc, ...echo.MiddlewareFunc) *echo.Route | 21 | Add(string, string, echo.HandlerFunc, ...echo.MiddlewareFunc) *echo.Route |
20 | } | 22 | } |
23 | |||
24 | // WantsTemplateStore is an interface for template helper functions that | ||
25 | // need access to the template store for the running echo instance. | ||
26 | type WantsTemplateStore interface { | ||
27 | ConfigureTemplateStore(fs.FS) | ||
28 | } | ||