Compare commits
No commits in common. "3ab7556b38f488853983631e13d322d15d7520a1" and "c65ff352dfe5c3b9ec932fc290a5141485bca6f3" have entirely different histories.
3ab7556b38
...
c65ff352df
|
|
@ -214,14 +214,9 @@ func GetRedis(c *gin.Context) {
|
||||||
//解析请求参数
|
//解析请求参数
|
||||||
var req SetRedisReq
|
var req SetRedisReq
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
if req.Option == "one" {
|
code, message := service.GetToolRedis(req.Key)
|
||||||
code, message := service.GetToolRedis(req.Key)
|
req.Value = message
|
||||||
req.Value = message
|
c.JSON(http.StatusOK, gin.H{"code": code, "message": message, "data": req})
|
||||||
c.JSON(http.StatusOK, gin.H{"code": code, "message": message, "data": req})
|
|
||||||
} else if req.Option == "all" {
|
|
||||||
code, message, data := service.GetAllRedis()
|
|
||||||
c.JSON(http.StatusOK, gin.H{"code": code, "message": message, "data": data})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -86,27 +86,6 @@ type ConfigStruct struct {
|
||||||
|
|
||||||
// 读取配置文件
|
// 读取配置文件
|
||||||
func ReadConfig(path string) error {
|
func ReadConfig(path string) error {
|
||||||
//查看配置文件是否存在,不存在则创建
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Config file not found!")
|
|
||||||
//创建默认配置
|
|
||||||
DefaultConfig()
|
|
||||||
//写入json文件
|
|
||||||
file, err := os.Create(path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error creating config file")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
encoder := json.NewEncoder(file)
|
|
||||||
err = encoder.Encode(&Config)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error encoding config")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
//读json文件
|
//读json文件
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -126,26 +105,3 @@ func ReadConfig(path string) error {
|
||||||
SigningKey = []byte(Config.TOKEN_SECRET)
|
SigningKey = []byte(Config.TOKEN_SECRET)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 默认配置
|
|
||||||
func DefaultConfig() {
|
|
||||||
Config.DB = 2
|
|
||||||
Config.MYSQL_DSN = MYSQL_DSN
|
|
||||||
Config.PG_DSN = ""
|
|
||||||
Config.REDIS_ADDR = REDIS_ADDR
|
|
||||||
Config.TOKEN_USE_REDIS = false
|
|
||||||
Config.REDIS_User_PW = false
|
|
||||||
Config.REDIS_PASSWORD = REDIS_PASSWORD
|
|
||||||
Config.REDIS_DB = REIDS_DB
|
|
||||||
Config.TOKEN_SECRET = TOKEN_SECRET
|
|
||||||
Config.CID_BASE_DIR = CID_BASE_DIR
|
|
||||||
Config.FILE_BASE_DIR = FILE_BASE_DIR
|
|
||||||
Config.MONITOR = false
|
|
||||||
Config.SERVER_SQL_LOG = false
|
|
||||||
Config.SERVER_PORT = "8083"
|
|
||||||
Config.LOG_SAVE_DAYS = 7
|
|
||||||
Config.SERVER_USER_TYPE = "master"
|
|
||||||
Config.MASTER_SERVER_DOMAIN = ""
|
|
||||||
Config.USER_SYNC_TIME = 86400
|
|
||||||
Config.SERVER_NAME = "default"
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,3 @@ func GetToolRedis(key string) (code int, message string) {
|
||||||
return proto.SuccessCode, val
|
return proto.SuccessCode, val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllRedis() (code int, msg string, data []worker.RedisInfo) {
|
|
||||||
data, err := worker.GetAllRedisInfo()
|
|
||||||
if err != nil {
|
|
||||||
return proto.OperationFailed, err.Error(), nil
|
|
||||||
}
|
|
||||||
return proto.SuccessCode, "success", data
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -460,39 +460,3 @@ func GetRedisSetUnion(key1 string, key2 string) []string {
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedisInfo struct {
|
|
||||||
Key string
|
|
||||||
Value string
|
|
||||||
Expire time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取所有的key和value,及其对应的过期时间
|
|
||||||
func GetAllRedisInfo() ([]RedisInfo, error) {
|
|
||||||
ctx := context.Background()
|
|
||||||
keys, err := RedisClient.Keys(ctx, "*").Result()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error getting key: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var redisInfos []RedisInfo
|
|
||||||
for _, key := range keys {
|
|
||||||
val, err := RedisClient.Get(ctx, key).Result()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error getting key: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
expire, err := RedisClient.TTL(ctx, key).Result()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error getting key: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
redisInfo := RedisInfo{
|
|
||||||
Key: key,
|
|
||||||
Value: val,
|
|
||||||
Expire: expire,
|
|
||||||
}
|
|
||||||
redisInfos = append(redisInfos, redisInfo)
|
|
||||||
}
|
|
||||||
return redisInfos, nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue