Files
spend-sparrow/internal/handler/middleware/cache_control.go
Tim Wundenberg 3e7251ef9d
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 5m51s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m46s
feat(observabillity): #115 integrate otel for metrics and traces
2025-06-07 12:25:07 +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)
})
}