summary refs log tree commit diff stats
path: root/svc/handlers.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-12-18 23:50:27 -0500
committerBen Morrison <ben@gbmor.dev>2019-12-18 23:50:27 -0500
commit982a521acd8537cf7a186b3d80e7b2588e6b15fc (patch)
tree28d69fb6c11965dc54ffc1ebf2defdf7051edebe /svc/handlers.go
parentefbc14fbc8c619eabd26d3bfe7e02e6490626d78 (diff)
downloadgetwtxt-982a521acd8537cf7a186b3d80e7b2588e6b15fc.tar.gz
refactored servStatic() to eliminate early return
Diffstat (limited to 'svc/handlers.go')
-rw-r--r--svc/handlers.go21
1 files 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
 }