enhance utilisation of postgres features
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-04-20 10:19:27 +10:00
parent 98e92a8264
commit 8ccf5a7009
28 changed files with 2836 additions and 422 deletions
+23 -3
View File
@@ -1,18 +1,38 @@
package middleware
import (
"vctp/version"
"net/http"
"strings"
"time"
"vctp/version"
)
// CacheMiddleware sets the Cache-Control header based on the version.
func CacheMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if version.Value == "dev" {
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
} else {
w.Header().Set("Cache-Control", "public, max-age=31536000")
cacheControl := "public, max-age=31536000"
if isVersionedAssetRequest(r) {
cacheControl += ", immutable"
}
w.Header().Set("Cache-Control", cacheControl)
w.Header().Set("Expires", time.Now().UTC().Add(365*24*time.Hour).Format(http.TimeFormat))
}
w.Header().Set("Vary", "Accept-Encoding")
next.ServeHTTP(w, r)
})
}
func isVersionedAssetRequest(r *http.Request) bool {
if r == nil {
return false
}
if r.URL.Query().Get("v") != "" {
return true
}
return strings.Contains(r.URL.Path, "@")
}