Files
spend-sparrow/handler/middleware/cache_control.go

27 lines
450 B
Go

package middleware
import (
"net/http"
"strings"
"me-fit/log"
)
func CacheControl(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
log.Info("path: %v", path)
cached := false
if strings.HasPrefix(path, "/static") {
cached = true
}
if !cached {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
}
next.ServeHTTP(w, r)
})
}