diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-12-18 23:50:27 -0500 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-12-18 23:50:27 -0500 |
commit | 982a521acd8537cf7a186b3d80e7b2588e6b15fc (patch) | |
tree | 28d69fb6c11965dc54ffc1ebf2defdf7051edebe | |
parent | efbc14fbc8c619eabd26d3bfe7e02e6490626d78 (diff) | |
download | getwtxt-982a521acd8537cf7a186b3d80e7b2588e6b15fc.tar.gz |
refactored servStatic() to eliminate early return
-rw-r--r-- | svc/handlers.go | 21 |
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 } |