summary refs log tree commit diff stats
path: root/svc/cache.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-09 04:00:21 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-09 04:00:21 -0400
commit7410b8cd74d0f702b087577b1793bcf541ac8371 (patch)
treedbc1aa568abc43fd7048d0587eecbb2a4d950cbb /svc/cache.go
parent7f76158b9565d804ada682c1a9aa83c22cb8de71 (diff)
downloadgetwtxt-7410b8cd74d0f702b087577b1793bcf541ac8371.tar.gz
init staticAssets explicitly on startup
Diffstat (limited to 'svc/cache.go')
-rw-r--r--svc/cache.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/svc/cache.go b/svc/cache.go
index 0963892..e2078d7 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -2,6 +2,7 @@ package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
 	"bytes"
+	"html/template"
 	"io/ioutil"
 	"os"
 	"sync"
@@ -24,6 +25,41 @@ type staticAssets struct {
 	cssMod   time.Time
 }
 
+func initTemplates() *template.Template {
+	confObj.Mu.RLock()
+	assetsDir := confObj.AssetsDir
+	confObj.Mu.RUnlock()
+
+	return template.Must(template.ParseFiles(assetsDir + "/tmpl/index.html"))
+}
+
+func initAssets() *staticAssets {
+	confObj.Mu.RLock()
+	defer confObj.Mu.RUnlock()
+
+	css, err := os.Open(confObj.AssetsDir + "/style.css")
+	errLog("", err)
+	cssStat, err := css.Stat()
+	errLog("", err)
+	cssData, err := ioutil.ReadAll(css)
+	errLog("", err)
+
+	indStat, err := os.Stat(confObj.AssetsDir + "/tmpl/index.html")
+	errLog("", err)
+
+	var b []byte
+	buf := bytes.NewBuffer(b)
+	errLog("", tmpls.ExecuteTemplate(buf, "index.html", confObj.Instance))
+
+	return &staticAssets{
+		mu:       sync.RWMutex{},
+		index:    buf.Bytes(),
+		indexMod: indStat.ModTime(),
+		css:      cssData,
+		cssMod:   cssStat.ModTime(),
+	}
+}
+
 func cacheTimer() bool {
 	confObj.Mu.RLock()
 	answer := time.Since(confObj.LastCache) > confObj.CacheInterval