diff options
-rw-r--r-- | cache.go | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/cache.go b/cache.go index 214d185..d598d19 100644 --- a/cache.go +++ b/cache.go @@ -1,6 +1,8 @@ package main import ( + "bytes" + "html/template" "io/ioutil" "log" "net" @@ -197,34 +199,35 @@ func pingAssets() { if err != nil { log.Printf("%v\n", err) } - /* - indexStat, err := os.Stat("assets/tmpl/index.html") + + indexStat, err := os.Stat("assets/tmpl/index.html") + if err != nil { + log.Printf("%v\n", err) + } + + indexMod := staticCache.indexMod + cssMod := staticCache.cssMod + + if !indexMod.Equal(indexStat.ModTime()) { + var err error + tmpls, err = template.ParseFiles("assets/tmpl/index.html") if err != nil { log.Printf("%v\n", err) } + var b []byte + buf := bytes.NewBuffer(b) - indexMod := staticCache.indexMod*/ - cssMod := staticCache.cssMod - /* - if !indexMod.Equal(indexStat.ModTime()) { - var err error - tmpls, err = template.ParseFiles("assets/tmpl/index.html") - if err != nil { - log.Printf("%v\n", err) - } - buf := bytes.NewBuffer(staticCache.index) + confObj.Mu.RLock() + err = tmpls.ExecuteTemplate(buf, "index.html", confObj.Instance) + confObj.Mu.RUnlock() + if err != nil { + log.Printf("%v\n", err) + } - confObj.Mu.RLock() - err = tmpls.ExecuteTemplate(buf, "index.html", confObj.Instance) - confObj.Mu.RUnlock() - if err != nil { - log.Printf("%v\n", err) - } + staticCache.index = buf.Bytes() + staticCache.indexMod = indexStat.ModTime() + } - staticCache.index = buf.Bytes() - staticCache.indexMod = indexStat.ModTime() - } - */ if !cssMod.Equal(cssStat.ModTime()) { css, err := ioutil.ReadFile("assets/style.css") |