diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-23 02:16:41 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-23 02:16:41 -0400 |
commit | 2b0d4a52363b8683a594066bf78786fca3ac881a (patch) | |
tree | 7b3a0f17e4e35d59600dea378179f6fbc4dda9d1 /cache.go | |
parent | cd635e6c6b009d6c9d6943ea7c850ca740172b65 (diff) | |
download | getwtxt-2b0d4a52363b8683a594066bf78786fca3ac881a.tar.gz |
caching some static assets
Diffstat (limited to 'cache.go')
-rw-r--r-- | cache.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cache.go b/cache.go index 2ed21f3..214d185 100644 --- a/cache.go +++ b/cache.go @@ -1,8 +1,10 @@ package main import ( + "io/ioutil" "log" "net" + "os" "strings" "time" @@ -185,3 +187,52 @@ func pullDatabase() { log.Printf("Error while pulling DB into registry cache: %v\n", err) } } + +// pingAssets checks if the local static assets +// need to be re-cached. If they do, they are +// pulled back into memory from disk. +func pingAssets() { + + cssStat, err := os.Stat("assets/style.css") + if err != nil { + log.Printf("%v\n", err) + } + /* + 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) + } + 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) + } + + staticCache.index = buf.Bytes() + staticCache.indexMod = indexStat.ModTime() + } + */ + if !cssMod.Equal(cssStat.ModTime()) { + + css, err := ioutil.ReadFile("assets/style.css") + if err != nil { + log.Printf("%v\n", err) + } + + staticCache.css = css + staticCache.cssMod = cssStat.ModTime() + } +} |