From 5cf45d21559eb4f8c69f57e9d50bcd4d00b9d430 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 20 Nov 2017 11:57:45 -0600 Subject: refactor template code (#7860) --- app/app.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index 49ac620e8..55fb43b30 100644 --- a/app/app.go +++ b/app/app.go @@ -4,6 +4,7 @@ package app import ( + "html/template" "net/http" "runtime/debug" "sync/atomic" @@ -52,7 +53,8 @@ type App struct { configFile string newStore func() store.Store - sessionCache *utils.Cache + htmlTemplateWatcher *utils.HTMLTemplateWatcher + sessionCache *utils.Cache } var appCount = 0 @@ -94,6 +96,12 @@ func New(options ...Option) *App { } } + if htmlTemplateWatcher, err := utils.NewHTMLTemplateWatcher("templates"); err != nil { + l4g.Error(utils.T("api.api.init.parsing_templates.error"), err) + } else { + app.htmlTemplateWatcher = htmlTemplateWatcher + } + app.Srv.Store = app.newStore() app.initJobs() @@ -125,6 +133,10 @@ func (a *App) Shutdown() { a.Srv.Store.Close() a.Srv = nil + if a.htmlTemplateWatcher != nil { + a.htmlTemplateWatcher.Close() + } + l4g.Info(utils.T("api.server.stop_server.stopped.info")) } @@ -327,6 +339,10 @@ func (a *App) WaitForGoroutines() { } } +func (a *App) HTMLTemplates() *template.Template { + return a.htmlTemplateWatcher.Templates() +} + func (a *App) Handle404(w http.ResponseWriter, r *http.Request) { err := model.NewAppError("Handle404", "api.context.404.app_error", nil, "", http.StatusNotFound) err.Translate(utils.T) -- cgit v1.2.3-1-g7c22