|
@ -31,8 +31,8 @@ func init() { |
|
|
dbPort, _ := beego.AppConfig.String("mysqlport") |
|
|
dbPort, _ := beego.AppConfig.String("mysqlport") |
|
|
maxIdleConn, _ := beego.AppConfig.Int("db_max_idle_conn") |
|
|
maxIdleConn, _ := beego.AppConfig.Int("db_max_idle_conn") |
|
|
maxOpenConn, _ := beego.AppConfig.Int("db_max_open_open") |
|
|
maxOpenConn, _ := beego.AppConfig.Int("db_max_open_open") |
|
|
orm.RegisterDriver("mysql", orm.DRMySQL) |
|
|
_ = orm.RegisterDriver("mysql", orm.DRMySQL) |
|
|
orm.RegisterDataBase("default", "mysql", |
|
|
_ = orm.RegisterDataBase("default", "mysql", |
|
|
dbUser+":"+dbPass+"@tcp("+dbHost+":"+dbPort+")/"+dbName+"?charset=utf8&parseTime=true&loc=Asia%2FShanghai", |
|
|
dbUser+":"+dbPass+"@tcp("+dbHost+":"+dbPort+")/"+dbName+"?charset=utf8&parseTime=true&loc=Asia%2FShanghai", |
|
|
) |
|
|
) |
|
|
orm.MaxIdleConnections(maxIdleConn) |
|
|
orm.MaxIdleConnections(maxIdleConn) |
|
@ -47,9 +47,16 @@ func init() { |
|
|
logs.Async() |
|
|
logs.Async() |
|
|
level, _ := beego.AppConfig.Int("logLevel") |
|
|
level, _ := beego.AppConfig.Int("logLevel") |
|
|
logs.SetLevel(level) |
|
|
logs.SetLevel(level) |
|
|
logs.SetLogger(logs.AdapterMultiFile, `{"filename":"./logs/yshop.log", |
|
|
_ = logs.SetLogger(logs.AdapterMultiFile, |
|
|
"level":6,"maxlines":0,"maxsize":0,"daily":true,"maxdays":30, |
|
|
`{ |
|
|
"separate":["emergency", "alert", "critical", "error", "warning", "notice", "info"]}`) |
|
|
"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") |
|
|
mytoken := ctx.Input.Header("Authorization") |
|
|
if len(mytoken) < bearerLength { |
|
|
if len(mytoken) < bearerLength { |
|
|
ctx.Output.Status = 401 |
|
|
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) |
|
|
true, true) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -87,7 +94,7 @@ func main() { |
|
|
usr, err := jwt.ValidateToken(token) |
|
|
usr, err := jwt.ValidateToken(token) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.Output.Status = 401 |
|
|
ctx.Output.Status = 401 |
|
|
ctx.Output.JSON(controllers.ErrMsg(err.Error(), 40001), |
|
|
_ = ctx.Output.JSON(controllers.ErrMsg(err.Error(), 40001), |
|
|
true, true) |
|
|
true, true) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -122,7 +129,7 @@ func checkPermission(url string, method string, token string) int { |
|
|
userMap, _ := redis.Get(key) |
|
|
userMap, _ := redis.Get(key) |
|
|
jsonStr := userMap[key] |
|
|
jsonStr := userMap[key] |
|
|
user := &models.SysUser{} |
|
|
user := &models.SysUser{} |
|
|
json.Unmarshal([]byte(jsonStr), user) |
|
|
_ = json.Unmarshal([]byte(jsonStr), user) |
|
|
|
|
|
|
|
|
index := untils.Contains(user.Permissions, permission) |
|
|
index := untils.Contains(user.Permissions, permission) |
|
|
|
|
|
|
|
|