mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 14:50:27 +00:00
Total visitor and page visits statistics page.
This commit is contained in:
@@ -27,6 +27,7 @@ func NewCache() *Cache {
|
||||
cache: make(map[string][]byte),
|
||||
hotReload: os.Getenv("MB_HOT_RELOAD") == "true",
|
||||
}
|
||||
logbuch.Debug("Template cache hot reload", logbuch.Fields{"hot_reload": cache.hotReload})
|
||||
cache.load()
|
||||
return cache
|
||||
}
|
||||
@@ -57,6 +58,12 @@ func (cache *Cache) Render(w http.ResponseWriter, name string, data interface{})
|
||||
cache.m.Lock()
|
||||
defer cache.m.Unlock()
|
||||
logbuch.Debug("Rendering template", logbuch.Fields{"name": name})
|
||||
|
||||
if cache.hotReload {
|
||||
logbuch.Debug("Reloading templates")
|
||||
cache.load()
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if err := cache.tpl.ExecuteTemplate(&buffer, name, data); err != nil {
|
||||
@@ -75,6 +82,18 @@ func (cache *Cache) Render(w http.ResponseWriter, name string, data interface{})
|
||||
}
|
||||
}
|
||||
|
||||
func (cache *Cache) RenderWithoutCache(w http.ResponseWriter, name string, data interface{}) {
|
||||
if cache.hotReload {
|
||||
logbuch.Debug("Reloading templates")
|
||||
cache.load()
|
||||
}
|
||||
|
||||
if err := cache.tpl.ExecuteTemplate(w, name, data); err != nil {
|
||||
logbuch.Error("Error executing template", logbuch.Fields{"err": err, "name": name})
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func (cache *Cache) Clear() {
|
||||
cache.m.Lock()
|
||||
defer cache.m.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user