From 59040a69d8e8ece32d47537d10202dc7a9c6b3d8 Mon Sep 17 00:00:00 2001 From: VivimanZhang Date: Fri, 31 Mar 2023 01:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BB=A3=E7=A0=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 415ea23..31c3ee1 100644 --- a/main.go +++ b/main.go @@ -31,8 +31,8 @@ func init() { dbPort, _ := beego.AppConfig.String("mysqlport") maxIdleConn, _ := beego.AppConfig.Int("db_max_idle_conn") maxOpenConn, _ := beego.AppConfig.Int("db_max_open_open") - orm.RegisterDriver("mysql", orm.DRMySQL) - orm.RegisterDataBase("default", "mysql", + _ = orm.RegisterDriver("mysql", orm.DRMySQL) + _ = orm.RegisterDataBase("default", "mysql", dbUser+":"+dbPass+"@tcp("+dbHost+":"+dbPort+")/"+dbName+"?charset=utf8&parseTime=true&loc=Asia%2FShanghai", ) orm.MaxIdleConnections(maxIdleConn) @@ -47,9 +47,16 @@ func init() { logs.Async() level, _ := beego.AppConfig.Int("logLevel") logs.SetLevel(level) - logs.SetLogger(logs.AdapterMultiFile, `{"filename":"./logs/yshop.log", - "level":6,"maxlines":0,"maxsize":0,"daily":true,"maxdays":30, - "separate":["emergency", "alert", "critical", "error", "warning", "notice", "info"]}`) + _ = logs.SetLogger(logs.AdapterMultiFile, + `{ + "filename":"./logs/yshop.log", + "level":6, + "maxlines":0, + "maxsize":0, + "daily":true, + "maxdays":30, + "separate":["emergency", "alert", "critical", "error", "warning", "notice", "info"] + }`) } @@ -79,7 +86,7 @@ func main() { mytoken := ctx.Input.Header("Authorization") if len(mytoken) < bearerLength { ctx.Output.Status = 401 - ctx.Output.JSON(controllers.ErrMsg("header Authorization has not Bearer token", 40001), + _ = ctx.Output.JSON(controllers.ErrMsg("header Authorization has not Bearer token", 40001), true, true) return } @@ -87,7 +94,7 @@ func main() { usr, err := jwt.ValidateToken(token) if err != nil { ctx.Output.Status = 401 - ctx.Output.JSON(controllers.ErrMsg(err.Error(), 40001), + _ = ctx.Output.JSON(controllers.ErrMsg(err.Error(), 40001), true, true) return } @@ -122,7 +129,7 @@ func checkPermission(url string, method string, token string) int { userMap, _ := redis.Get(key) jsonStr := userMap[key] user := &models.SysUser{} - json.Unmarshal([]byte(jsonStr), user) + _ = json.Unmarshal([]byte(jsonStr), user) index := untils.Contains(user.Permissions, permission)