diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-13 22:22:05 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-13 22:22:13 -0400 |
commit | ec2c4edb9d47dfee9d402bf63d3d006900fbc5a1 (patch) | |
tree | 139d8cb877e2f43ff717965046cd4ff3f5c9135c | |
parent | 920306cbcad3df05e01699cd19f3767e069ab139 (diff) | |
download | getwtxt-ec2c4edb9d47dfee9d402bf63d3d006900fbc5a1.tar.gz |
send etag for index. sha256 of template mod time.
-rw-r--r-- | handlers.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/handlers.go b/handlers.go index 961ac4f..f00eec5 100644 --- a/handlers.go +++ b/handlers.go @@ -14,8 +14,15 @@ import ( // handles "/" func indexHandler(w http.ResponseWriter, _ *http.Request) { + indextmpl, err := os.Stat("assets/tmpl/index.html") + if err != nil { + log.Printf("Couldn't stat index template, sending empty ETag ... %v\n", err) + } + + etag := fmt.Sprintf("%x", sha256.Sum256([]byte(indextmpl.ModTime().String()))) + w.Header().Set("ETag", "\""+etag+"\"") w.Header().Set("Content-Type", htmlutf8) - err := tmpls.ExecuteTemplate(w, "index.html", confObj.Instance) + err = tmpls.ExecuteTemplate(w, "index.html", confObj.Instance) if err != nil { log.Printf("Error writing to HTTP stream: %v\n", err) http.Error(w, err.Error(), http.StatusInternalServerError) |