Added support for cache control as a gin-gonic middleware
This commit is contained in:
16
middleware.go
Normal file
16
middleware.go
Normal file
@ -0,0 +1,16 @@
|
||||
package precompiler
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GinMiddleware is used to set the cache-control header for all files under the specified asset path (including leading slash)
|
||||
func GinMiddleware(assetPath string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if strings.HasPrefix(c.Request.URL.Path, assetPath) {
|
||||
c.Header("cache-control", "max-age=315360000; public")
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user