24 lines
492 B
Go
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)
|
|
})
|
|
}
|