Skip to content

Commit

Permalink
Merge pull request #42 from issueye/dev
Browse files Browse the repository at this point in the history
注册gob数据类型 & 防止前端 js 文件不能被访问
  • Loading branch information
newpanjing authored Jul 24, 2022
2 parents ef13237 + 0e354fc commit 4c6a67f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions searcher/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{})
}
8 changes: 8 additions & 0 deletions web/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"gofound/web/admin"
"gofound/web/middleware"
"log"
"mime"
"strings"

"github.com/gin-contrib/gzip"
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit 4c6a67f

Please sign in to comment.