From 69adb2159f0c050d18d075241945d3224dca5d30 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Tue, 11 Jun 2019 20:10:58 -0400 Subject: cleaned up staticHandler --- svc/handlers.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/svc/handlers.go b/svc/handlers.go index 9ab9cdb..def01ad 100644 --- a/svc/handlers.go +++ b/svc/handlers.go @@ -19,36 +19,34 @@ func getEtag(modtime time.Time) string { } func servStatic(w http.ResponseWriter, isCSS bool) error { + pingAssets() + + staticCache.mu.RLock() if isCSS { etag := getEtag(staticCache.cssMod) w.Header().Set("ETag", "\""+etag+"\"") w.Header().Set("Content-Type", cssutf8) _, err := w.Write(staticCache.css) + staticCache.mu.RUnlock() return err } + etag := getEtag(staticCache.indexMod) w.Header().Set("ETag", "\""+etag+"\"") w.Header().Set("Content-Type", htmlutf8) _, err := w.Write(staticCache.index) + staticCache.mu.RUnlock() return err } // handles "/" and "/css" func staticHandler(w http.ResponseWriter, r *http.Request) { - pingAssets() - - // Take the hex-encoded sha256 sum of the index template's mod time - // to send as an ETag. If an error occurred when grabbing the file info, - // the ETag will be empty. - staticCache.mu.RLock() isCSS := strings.Contains(r.URL.Path, "css") - err := servStatic(w, isCSS) - if err != nil { - staticCache.mu.RUnlock() + + if err := servStatic(w, isCSS); err != nil { errHTTP(w, r, err, http.StatusInternalServerError) return } - staticCache.mu.RUnlock() log200(r) } -- cgit 1.4.1-2-gfad0