From 0e354fcd25e45e27089d29b9c838f25c9f2caa70 Mon Sep 17 00:00:00 2001 From: issueye Date: Tue, 21 Jun 2022 17:07:56 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B3=A8=E5=86=8Cgob=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=B1=BB=E5=9E=8B=202=E3=80=81=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=20js=20=E6=96=87=E4=BB=B6=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E8=A2=AB=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- searcher/utils/utils.go | 7 +++++++ web/router/router.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/searcher/utils/utils.go b/searcher/utils/utils.go index b2d04ce..8579898 100644 --- a/searcher/utils/utils.go +++ b/searcher/utils/utils.go @@ -227,3 +227,10 @@ func RemoveSpace(str string) string { reg := regexp.MustCompile(`\s+`) return reg.ReplaceAllString(str, "") } + +// init 注册数据类型 +// 防止 gob: type not registered for interface: map[string]interface {} +func init() { + gob.Register(map[string]interface{}{}) + gob.Register([]interface{}{}) +} diff --git a/web/router/router.go b/web/router/router.go index 9ad86ed..e298c68 100644 --- a/web/router/router.go +++ b/web/router/router.go @@ -5,6 +5,7 @@ import ( "gofound/web/admin" "gofound/web/middleware" "log" + "mime" "strings" "github.com/gin-contrib/gzip" @@ -38,6 +39,13 @@ func SetupRouter() *gin.Engine { log.Println("Enable Auth:", global.CONFIG.Auth) } + // 告诉服务.js文件的MIME类型 + err := mime.AddExtensionType(".js", "application/javascript") + // 如果存在错误则需要马上抛出 + if err != nil { + panic("添加扩展类型 mime 错误,错误原因:" + err.Error()) + } + //注册admin if global.CONFIG.EnableAdmin { admin.Register(router, handlers...)