Browse Source

update: LoadAll函数优化

main
SliverHorn 3 years ago
parent
commit
4ae6ed8667
  1. 16
      server/service/system/jwt_black_list.go

16
server/service/system/jwt_black_list.go

@ -2,6 +2,7 @@ package system
import ( import (
"context" "context"
"go.uber.org/zap"
"time" "time"
"github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/global"
@ -22,8 +23,7 @@ func (jwtService *JwtService) JsonInBlacklist(jwtList system.JwtBlacklist) (err
if err != nil { if err != nil {
return return
} }
global.BlackCache.SetDefault(jwtList.Jwt, struct {
}{})
global.BlackCache.SetDefault(jwtList.Jwt, struct{}{})
return return
} }
@ -67,12 +67,12 @@ func (jwtService *JwtService) SetRedisJWT(jwt string, userName string) (err erro
func LoadAll() { func LoadAll() {
var data []string var data []string
err := global.GVA_DB.Find(&system.JwtBlacklist{}).Select("jwt").Find(&data).Error
err := global.GVA_DB.Model(&system.JwtBlacklist{}).Select("jwt").Find(&data).Error
if err != nil { if err != nil {
// 从db加载jwt数据
for i := range data {
global.BlackCache.SetDefault(data[i], struct {
}{})
}
global.GVA_LOG.Error("加载数据库jwt黑名单失败!", zap.Error(err))
return
} }
for i := 0; i < len(data); i++ {
global.BlackCache.SetDefault(data[i], struct{}{})
} // jwt黑名单 加入 BlackCache 中
} }
Loading…
Cancel
Save