summary refs log tree commit diff stats
path: root/cache.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-23 02:16:41 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-23 02:16:41 -0400
commit2b0d4a52363b8683a594066bf78786fca3ac881a (patch)
tree7b3a0f17e4e35d59600dea378179f6fbc4dda9d1 /cache.go
parentcd635e6c6b009d6c9d6943ea7c850ca740172b65 (diff)
downloadgetwtxt-2b0d4a52363b8683a594066bf78786fca3ac881a.tar.gz
caching some static assets
Diffstat (limited to 'cache.go')
-rw-r--r--cache.go51
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()
+	}
+}