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:29:36 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-23 02:29:36 -0400
commit25972a6bfa296f37a4f658b2b848705fbaaf3bbd (patch)
tree1d2fa939d042f891644bb1626d001df0dcab248c /cache.go
parent2b0d4a52363b8683a594066bf78786fca3ac881a (diff)
downloadgetwtxt-25972a6bfa296f37a4f658b2b848705fbaaf3bbd.tar.gz
caching all static assets
Diffstat (limited to 'cache.go')
-rw-r--r--cache.go47
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")