aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/static/handler.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-06-07 19:33:07 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-06-07 19:33:07 +0200
commitc7a8aa113a914e70e027fea93265c7232b865b5e (patch)
treed5514cb6e5f49838ff75e814b64652ad244cf0ef /pkg/handler/static/handler.go
parent18aa098f50e2a2c7db01dd4d04dde460fd40f5d5 (diff)
downloadcerrado-c7a8aa113a914e70e027fea93265c7232b865b5e.tar.gz
cerrado-c7a8aa113a914e70e027fea93265c7232b865b5e.tar.bz2
cerrado-c7a8aa113a914e70e027fea93265c7232b865b5e.zip
feat: Add compression
Diffstat (limited to 'pkg/handler/static/handler.go')
-rw-r--r--pkg/handler/static/handler.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/handler/static/handler.go b/pkg/handler/static/handler.go
index a8b4583..5155068 100644
--- a/pkg/handler/static/handler.go
+++ b/pkg/handler/static/handler.go
@@ -2,8 +2,11 @@ package static
import (
"io/fs"
+ "mime"
"net/http"
+ "path/filepath"
+ "git.gabrielgio.me/cerrado/pkg/ext"
"git.gabrielgio.me/cerrado/static"
)
@@ -14,8 +17,12 @@ func ServeStaticHandler() (func(w http.ResponseWriter, r *http.Request), error)
}
return func(w http.ResponseWriter, r *http.Request) {
- f := r.PathValue("file")
-
+ var (
+ f = r.PathValue("file")
+ e = filepath.Ext(f)
+ m = mime.TypeByExtension(e)
+ )
+ ext.SetMIME(w, m)
http.ServeFileFS(w, r, staticFs, f)
}, nil
}