Added support for cache control as a gin-gonic middleware

This commit is contained in:
2018-11-26 22:19:46 -06:00
parent 9891169704
commit fca59e037e

16
middleware.go Normal file
View 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")
}
}
}