Files
Message-Push-Nest/middleware/static.go
T

19 lines
438 B
Go
Raw Normal View History

2024-01-02 14:45:34 +08:00
package middleware
import (
"github.com/gin-gonic/gin"
"strings"
)
// StaticCacheMiddleware add embed file static cache
func StaticCacheMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
// Apply the Cache-Control header to the static files
if strings.HasPrefix(c.Request.URL.Path, "/assets/") {
c.Header("Cache-Control", "private, max-age=86400")
}
// Continue to the next middleware or handler
c.Next()
}
}