diff --git a/internal/router/router.go b/internal/router/router.go index 4c2c53ba7..6b8bafb75 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -47,8 +47,6 @@ type Router interface { AttachMiddleware(handler gin.HandlerFunc) // Attach 404 NoRoute handler AttachNoRouteHandler(handler gin.HandlerFunc) - // Set Template function map - SetTemplateFuncMap(functions template.FuncMap) // Start the router Start() // Stop the router @@ -101,11 +99,6 @@ func (r *router) Stop(ctx context.Context) error { return r.srv.Shutdown(ctx) } -// Set Template function map -func (r *router) SetTemplateFuncMap(functions template.FuncMap) { - r.engine.SetFuncMap(functions) -} - // New returns a new Router with the specified configuration, using the given logrus logger. // // The given DB is only used in the New function for parsing config values, and is not otherwise @@ -134,6 +127,9 @@ func New(cfg *config.Config, db db.DB, logger *logrus.Logger) (Router, error) { return nil, err } + // set template functions + loadTemplateFunctions(engine); + // load templates onto the engine if err := loadTemplates(cfg, engine); err != nil { return nil, err diff --git a/internal/router/template.go b/internal/router/template.go index cd1eb11db..8f3e76573 100644 --- a/internal/router/template.go +++ b/internal/router/template.go @@ -21,3 +21,13 @@ func loadTemplates(cfg *config.Config, engine *gin.Engine) error { engine.LoadHTMLGlob(tmPath) return nil } + +func noescape(str string) template.HTML { + return template.HTML(str) +} + +func loadTemplateFunctions(engine *gin.Engine) { + return r.engine.SetFuncMap(template.FuncMap{ + "noescape": noescape, + }) +} \ No newline at end of file diff --git a/internal/web/base.go b/internal/web/base.go index 10c4d0afa..b1784ce89 100644 --- a/internal/web/base.go +++ b/internal/web/base.go @@ -85,10 +85,6 @@ func (m *Module) NotFoundHandler(c *gin.Context) { }) } -func noescape(str string) template.HTML { - return template.HTML(str) -} - // Route satisfies the RESTAPIModule interface func (m *Module) Route(s router.Router) error { @@ -106,10 +102,6 @@ func (m *Module) Route(s router.Router) error { // 404 handler s.AttachNoRouteHandler(m.NotFoundHandler) - s.SetTemplateFuncMap(template.FuncMap{ - "noescape": noescape, - }) - if err != nil { return fmt.Errorf("error setting router FuncMap: %s", err) }