Files
spend-sparrow/internal/handler/middleware/cache_control.go
Tim Wundenberg 587de563f9
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 3m59s
feat(observabillity): #115 migrate to otel
2025-06-05 09:11:31 +02:00

24 lines
492 B
Go

package middleware
import (
"net/http"
"strings"
"go.opentelemetry.io/otel"
)
func CacheControl(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
counter, _ := otel.Meter("").Int64Counter("spend.sparrow.test")
counter.Add(r.Context(), 1)
shouldCache := strings.HasPrefix(r.URL.Path, "/static")
if !shouldCache {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
}
next.ServeHTTP(w, r)
})
}