add static cache-control

This commit is contained in:
aichy126
2023-04-24 18:23:39 +08:00
parent c3c7eb962d
commit 587f0aa1e3
2 changed files with 16 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
package middleware
import (
"strings"
"github.com/gin-gonic/gin"
)
func HeadersByRequestURI() gin.HandlerFunc {
return func(c *gin.Context) {
if strings.HasPrefix(c.Request.RequestURI, "/static/") {
c.Header("cache-control", "public, max-age=31536000")
}
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ func NewHTTPServer(debug bool,
html, _ := fs.Sub(ui.Template, "template")
htmlTemplate := template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*"))
r.SetHTMLTemplate(htmlTemplate)
r.Use(middleware.HeadersByRequestURI())
viewRouter.Register(r)
rootGroup := r.Group("")