wp-go/internal/middleware/staticFileCache.go

27 lines
520 B
Go
Raw Normal View History

2022-09-14 05:28:31 +00:00
package middleware
import (
2023-02-05 13:29:09 +00:00
"fmt"
"github.com/fthvgb1/wp-go/internal/pkg/config"
2022-09-14 05:28:31 +00:00
"github.com/gin-gonic/gin"
"strings"
)
2023-02-05 13:29:09 +00:00
var path = map[string]struct{}{
2023-02-06 09:58:24 +00:00
"wp-includes": {},
2023-02-05 13:29:09 +00:00
"wp-content": {},
"favicon.ico": {},
}
2022-09-14 05:28:31 +00:00
func SetStaticFileCache(c *gin.Context) {
f := strings.Split(strings.TrimLeft(c.FullPath(), "/"), "/")
2023-02-05 13:29:09 +00:00
if _, ok := path[f[0]]; ok {
t := config.GetConfig().CacheTime.CacheControl
if t > 0 {
c.Header("Cache-Control", fmt.Sprintf("private, max-age=%d", int(t.Seconds())))
}
2022-09-14 05:28:31 +00:00
}
2023-02-05 13:29:09 +00:00
2022-09-14 13:30:59 +00:00
c.Next()
2022-09-14 05:28:31 +00:00
}