From 982a521acd8537cf7a186b3d80e7b2588e6b15fc Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Wed, 18 Dec 2019 23:50:27 -0500 Subject: refactored servStatic() to eliminate early return --- svc/handlers.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/svc/handlers.go b/svc/handlers.go index 645b3fc..cf9d279 100644 --- a/svc/handlers.go +++ b/svc/handlers.go @@ -46,18 +46,23 @@ func servStatic(w http.ResponseWriter, isCSS bool) error { staticCache.mu.RLock() defer staticCache.mu.RUnlock() + var etag string + var body []byte + var contentType string + if isCSS { - etag := getEtagFromTime(staticCache.cssMod) - w.Header().Set("ETag", "\""+etag+"\"") - w.Header().Set("Content-Type", cssutf8) - _, err := w.Write(staticCache.css) - return err + etag = getEtagFromTime(staticCache.cssMod) + contentType = cssutf8 + body = staticCache.css + } else { + etag = getEtagFromTime(staticCache.indexMod) + contentType = htmlutf8 + body = staticCache.index } - etag := getEtagFromTime(staticCache.indexMod) w.Header().Set("ETag", "\""+etag+"\"") - w.Header().Set("Content-Type", htmlutf8) - _, err := w.Write(staticCache.index) + w.Header().Set("Content-Type", contentType) + _, err := w.Write(body) return err } -- cgit 1.4.1-2-gfad0