refactor template code (#7860)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
7eb7509393
Коммит
5cf45d2155
18
app/app.go
18
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)
|
||||
|
||||
Ссылка в новой задаче
Block a user