add cache control

This commit is contained in:
yourok
2023-12-22 17:03:45 +03:00
parent b439f21958
commit cf57af2cf1

View File

@@ -82,11 +82,16 @@ func writeRoute(fname string, fmap map[string]string) {
embedStr := `package template embedStr := `package template
import ( import (
"crypto/md5"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func RouteWebPages(route *gin.RouterGroup) { func RouteWebPages(route *gin.RouterGroup) {
route.GET("/", func(c *gin.Context) { route.GET("/", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Indexhtml))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "text/html; charset=utf-8", Indexhtml) c.Data(200, "text/html; charset=utf-8", Indexhtml)
}) })
` `
@@ -108,6 +113,9 @@ func RouteWebPages(route *gin.RouterGroup) {
} }
embedStr += ` embedStr += `
route.GET("` + link + `", func(c *gin.Context) { route.GET("` + link + `", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(` + fmap[link] + `))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "` + fmime + `", ` + fmap[link] + `) c.Data(200, "` + fmime + `", ` + fmap[link] + `)
}) })
` `