diff --git a/middleware.go b/middleware.go new file mode 100644 index 0000000..3b7fae8 --- /dev/null +++ b/middleware.go @@ -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") + } + } +}