优化全局变量
This commit is contained in:
Vendored
+6
-6
@@ -1,22 +1,22 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/constant"
|
||||
"cutego/refs"
|
||||
)
|
||||
|
||||
// RemoveList 批量根据Key删除数据
|
||||
// @Param list []string 键合集
|
||||
func RemoveList(list []string) {
|
||||
modules.RedisDB.DELALL(list)
|
||||
refs.RedisDB.DELALL(list)
|
||||
}
|
||||
|
||||
// RemoveKey 根据key删除
|
||||
// @Param key 键
|
||||
// @Return int 删除的数量
|
||||
func RemoveCache(key string) int {
|
||||
del, err := modules.RedisDB.DEL(key)
|
||||
del, err := refs.RedisDB.DEL(key)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func RemoveCache(key string) int {
|
||||
// @Param key 键
|
||||
// @Return string 值
|
||||
func GetCache(key string) string {
|
||||
val, err := modules.RedisDB.GET(key)
|
||||
val, err := refs.RedisDB.GET(key)
|
||||
if err != nil {
|
||||
common.ErrorLog(constant.RedisConst{}.GetRedisError(), err.Error())
|
||||
return ""
|
||||
@@ -40,7 +40,7 @@ func GetCache(key string) string {
|
||||
// @Param value 值
|
||||
// @Return 新增的行数
|
||||
func SetCache(key string, value interface{}) int {
|
||||
n, err := modules.RedisDB.SET(key, common.StructToJson(value))
|
||||
n, err := refs.RedisDB.SET(key, common.StructToJson(value))
|
||||
if err != nil {
|
||||
common.ErrorLog(constant.RedisConst{}.GetRedisError(), err.Error())
|
||||
return 0
|
||||
@@ -54,5 +54,5 @@ func SetCache(key string, value interface{}) int {
|
||||
// @Param sec 过期时间(单位: 秒)
|
||||
// @Return 新增的行数
|
||||
func SetCacheTTL(key string, value interface{}, sec int) {
|
||||
modules.RedisDB.SETEX(key, sec, common.StructToJson(value))
|
||||
refs.RedisDB.SETEX(key, sec, common.StructToJson(value))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package gin
|
||||
|
||||
import (
|
||||
"cutego/modules/core/router"
|
||||
"cutego/pkg/filter"
|
||||
"cutego/pkg/jwt"
|
||||
"cutego/pkg/middleware"
|
||||
"cutego/pkg/middleware/logger"
|
||||
"cutego/pkg/websocket"
|
||||
"cutego/refs"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fmt.Println("CoolGin init...")
|
||||
refs.CoolGin = gin.New()
|
||||
refs.CoolGin.Use(gin.Logger())
|
||||
refs.CoolGin.Use(gin.Recovery())
|
||||
refs.CoolGin.Use(logger.LoggerToFile())
|
||||
refs.CoolGin.Use(middleware.Recover)
|
||||
refs.CoolGin.Use(jwt.JWTAuth())
|
||||
refs.CoolGin.Use(filter.DemoHandler())
|
||||
// websocket
|
||||
refs.CoolGin.GET("/websocket", websocket.HandleWebSocketMessage)
|
||||
// v1版本api
|
||||
v1Router := refs.CoolGin.Group("/api/v1")
|
||||
// 加载: 模块路由
|
||||
router.LoadCoreRouter(v1Router)
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/response"
|
||||
"cutego/pkg/cache"
|
||||
"cutego/pkg/config"
|
||||
"cutego/refs"
|
||||
"errors"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -52,7 +52,7 @@ func JWTAuth() gin.HandlerFunc {
|
||||
}
|
||||
singleTag := config.AppEnvConfig.Login.Single
|
||||
if singleTag {
|
||||
token, err := modules.RedisDB.GET(claims.UserInfo.UserName)
|
||||
token, err := refs.RedisDB.GET(claims.UserInfo.UserName)
|
||||
if err == nil {
|
||||
if !(token == currentTokenStr) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/response"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/config"
|
||||
"cutego/pkg/jwt"
|
||||
"cutego/refs"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
)
|
||||
@@ -32,7 +32,7 @@ func CheckLockToken(c *gin.Context) bool {
|
||||
if config.AppEnvConfig.Login.Single {
|
||||
// 获取redis中的token数据
|
||||
info := GetUserInfo(c)
|
||||
get, err := modules.RedisDB.GET(info.UserName)
|
||||
get, err := refs.RedisDB.GET(info.UserName)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return false
|
||||
@@ -49,7 +49,7 @@ func CheckLockToken(c *gin.Context) bool {
|
||||
}
|
||||
|
||||
// CheckIsAdmin 判断是否是超级管理员
|
||||
func CheckIsAdmin(user *dataobject.SysUser) bool {
|
||||
func CheckIsAdmin(user *entity.SysUser) bool {
|
||||
if user.UserId == 1 {
|
||||
return true
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user