24 lines
406 B
Go
24 lines
406 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func CacheControl(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
path := r.URL.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)
|
|
})
|
|
}
|