summary refs log tree commit diff stats
path: root/handlers.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 /handlers.go
parentcd635e6c6b009d6c9d6943ea7c850ca740172b65 (diff)
downloadgetwtxt-2b0d4a52363b8683a594066bf78786fca3ac881a.tar.gz
caching some static assets
Diffstat (limited to 'handlers.go')
-rw-r--r--handlers.go24
1 files changed, 4 insertions, 20 deletions
diff --git a/handlers.go b/handlers.go
index 7f05f8f..1e01619 100644
--- a/handlers.go
+++ b/handlers.go
@@ -3,7 +3,6 @@ package main
 import (
 	"crypto/sha256"
 	"fmt"
-	"io/ioutil"
 	"log"
 	"net/http"
 	"os"
@@ -175,30 +174,15 @@ func apiTagsHandler(w http.ResponseWriter, r *http.Request) {
 // files aren't served directly.
 func cssHandler(w http.ResponseWriter, r *http.Request) {
 
-	// read the raw bytes of the stylesheet
-	css, err := ioutil.ReadFile("assets/style.css")
-	if err != nil {
-		if os.IsNotExist(err) {
-			log404(w, r, err)
-			return
-		}
-		log500(w, r, err)
-		return
-	}
-
-	// Get the mod time for the etag header
-	stat, err := os.Stat("assets/style.css")
-	if err != nil {
-		log.Printf("Couldn't stat CSS file to send ETag header: %v\n", err)
-	}
-
 	// Sending the sha256 sum of the modtime in hexadecimal for the ETag header
-	etag := fmt.Sprintf("%x", sha256.Sum256([]byte(stat.ModTime().String())))
+	etag := fmt.Sprintf("%x", sha256.Sum256([]byte(staticCache.cssMod.String())))
 
 	w.Header().Set("ETag", "\""+etag+"\"")
 	w.Header().Set("Content-Type", cssutf8)
 
-	n, err := w.Write(css)
+	pingAssets()
+
+	n, err := w.Write(staticCache.css)
 	if err != nil || n == 0 {
 		log500(w, r, err)
 		return