feat: optimization waf map load (#10730)

This commit is contained in:
CityFun 2025-10-23 16:00:23 +08:00 committed by GitHub
parent 86b0e01d9d
commit 274fd526b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 37 deletions

View file

@ -10,3 +10,6 @@ var Assets embed.FS
//go:embed favicon.png
var Favicon embed.FS
//go:embed static/*
var Static embed.FS

View file

@ -31,8 +31,9 @@ func setWebStatic(rootRouter *gin.RouterGroup) {
rootRouter.StaticFS("/public", http.FS(web.Favicon))
rootRouter.StaticFS("/favicon.ico", http.FS(web.Favicon))
RegisterImages(rootRouter)
setStaticResource(rootRouter)
rootRouter.GET("/assets/*filepath", func(c *gin.Context) {
c.Writer.Header().Set("Cache-Control", fmt.Sprintf("private, max-age=%d", 3600))
c.Writer.Header().Set("Cache-Control", fmt.Sprintf("private, max-age=%d", 2628000))
if c.Request.URL.Path[len(c.Request.URL.Path)-1] == '/' {
c.AbortWithStatus(http.StatusForbidden)
return
@ -133,3 +134,18 @@ func RegisterImages(rootRouter *gin.RouterGroup) {
_, _ = io.Copy(c.Writer, f)
})
}
func setStaticResource(rootRouter *gin.RouterGroup) {
rootRouter.GET("/api/v2/static/*filename", func(c *gin.Context) {
c.Writer.Header().Set("Cache-Control", fmt.Sprintf("private, max-age=%d", 2628000))
filename := c.Param("filename")
filePath := "static" + filename
data, err := web.Static.ReadFile(filePath)
if err != nil {
c.AbortWithStatus(http.StatusNotFound)
return
}
c.Writer.Header().Set("Content-Type", "application/json; charset=utf-8")
c.Writer.Write(data)
})
}

View file

@ -1,36 +0,0 @@
{
"Anhui": "安徽",
"Beijing": "北京",
"Fujian": "福建",
"Gansu": "甘肃",
"Guangdong": "广东",
"Guangxi": "广西",
"Guizhou": "贵州",
"Hainan": "海南",
"Hebei": "河北",
"Henan": "河南",
"Heilongjiang": "黑龙江",
"Hubei": "湖北",
"Hunan": "湖南",
"Jilin": "吉林",
"Jiangsu": "江苏",
"Jiangxi": "江西",
"Liaoning": "辽宁",
"Inner Mongolia": "内蒙古",
"Ningxia": "宁夏",
"Qinghai": "青海",
"Shandong": "山东",
"Shanxi": "山西",
"Shaanxi": "陕西",
"Shanghai": "上海",
"Sichuan": "四川",
"Tianjin": "天津",
"Tibet": "西藏",
"Xinjiang": "新疆",
"Yunnan": "云南",
"Zhejiang": "浙江",
"Chongqing": "重庆",
"HongKong": "香港",
"Macao": "澳门",
"Taiwan": "台湾"
}