From 22b26da0dc4f3caf95e1cc71f45b4f4247d77d69 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Fri, 3 Jul 2026 02:59:53 +0200 Subject: [PATCH] feat: wire compression and cache middlewares into router --- internal/server/server.go | 2 +- internal/server/static_delivery.go | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/internal/server/server.go b/internal/server/server.go index 30602830..d5813233 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -26,7 +26,7 @@ func ProvideRouter(cfg config.Config, htmlRender render.HTMLRender) *gin.Engine gin.SetMode(cfg.GinMode) } r := gin.New() - r.Use(CORSMiddlewareWithConfig(cfg), RequestContextMiddleware(), audit.ContextMiddleware(), RequestLogger(), gin.Recovery()) + r.Use(CORSMiddlewareWithConfig(cfg), RequestContextMiddleware(), audit.ContextMiddleware(), RequestLogger(), CompressionMiddleware(), StaticCacheMiddleware(), gin.Recovery()) r.NoRoute(func(c *gin.Context) { if acceptsHTML(c) { c.HTML(http.StatusNotFound, "not_found.gohtml", gin.H{ diff --git a/internal/server/static_delivery.go b/internal/server/static_delivery.go index fd4ca7a0..fd3f00f1 100644 --- a/internal/server/static_delivery.go +++ b/internal/server/static_delivery.go @@ -81,19 +81,16 @@ type cacheControlWriter struct { policy string } -//nolint:unused func (w *cacheControlWriter) WriteHeader(status int) { w.apply(status) w.ResponseWriter.WriteHeader(status) } -//nolint:unused func (w *cacheControlWriter) WriteHeaderNow() { w.apply(w.Status()) w.ResponseWriter.WriteHeaderNow() } -//nolint:unused func (w *cacheControlWriter) Write(data []byte) (int, error) { if !w.Written() { w.apply(w.Status()) @@ -101,7 +98,6 @@ func (w *cacheControlWriter) Write(data []byte) (int, error) { return w.ResponseWriter.Write(data) } -//nolint:unused func (w *cacheControlWriter) WriteString(data string) (int, error) { if !w.Written() { w.apply(w.Status()) @@ -109,7 +105,6 @@ func (w *cacheControlWriter) WriteString(data string) (int, error) { return w.ResponseWriter.WriteString(data) } -//nolint:unused func (w *cacheControlWriter) Flush() { if !w.Written() { w.apply(w.Status()) @@ -117,12 +112,10 @@ func (w *cacheControlWriter) Flush() { w.ResponseWriter.Flush() } -//nolint:unused func (w *cacheControlWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { return w.ResponseWriter.Hijack() } -//nolint:unused func (w *cacheControlWriter) apply(status int) { if status >= http.StatusOK && status < http.StatusMultipleChoices || status == http.StatusNotModified { w.Header().Set("Cache-Control", w.policy) @@ -131,7 +124,6 @@ func (w *cacheControlWriter) apply(status int) { } } -//nolint:unused func StaticCacheMiddleware() gin.HandlerFunc { return func(c *gin.Context) { if c.Request.Method != http.MethodGet && c.Request.Method != http.MethodHead {