|
@@ -66,11 +66,10 @@ func syscfg_redis_list(resp http.ResponseWriter, req *http.Request) {
|
|
|
mdlRedisCfg := model.NewRedisCfg(Db)
|
|
|
rows, err := mdlRedisCfg.GetAll(-1)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 1, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(1, err.Error()))
|
|
|
} else {
|
|
|
- json, _ := json.Marshal(SyscfgRedisListRet{Errno: 0, Error: "", Data: rows})
|
|
|
- resp.Write(json)
|
|
|
+ ret, _ := json.Marshal(SyscfgRedisListRet{Errno: 0, Error: "", Data: rows})
|
|
|
+ resp.Write(ret)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -82,24 +81,21 @@ func syscfg_redis_get(resp http.ResponseWriter, req *http.Request) {
|
|
|
req.ParseForm()
|
|
|
idStr := req.Form.Get("id")
|
|
|
if idStr == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 1, Error: "ID不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(1, "ID不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
id, err := strconv.Atoi(idStr)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 2, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(2, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
mdlRedisCfg := model.NewRedisCfg(Db)
|
|
|
item, err := mdlRedisCfg.Get(int64(id))
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 3, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(3, err.Error()))
|
|
|
} else {
|
|
|
- json, _ := json.Marshal(SyscfgRedisGetRet{Errno: 0, Error: "", Data: item})
|
|
|
- resp.Write(json)
|
|
|
+ ret, _ := json.Marshal(SyscfgRedisGetRet{Errno: 0, Error: "", Data: item})
|
|
|
+ resp.Write(ret)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -116,7 +112,7 @@ func syscfg_redis_set(resp http.ResponseWriter, req *http.Request) {
|
|
|
MaxConnectWait := req.PostForm.Get("MaxConnectWait")
|
|
|
MaxStatusFailed := req.PostForm.Get("MaxStatusFailed")
|
|
|
MinMemoryFree := req.PostForm.Get("MinMemoryFree")
|
|
|
- MinMemoryFreePC := req.PostForm.Get("MinMemoryFreePC")
|
|
|
+ StepMemoryIncrease := req.PostForm.Get("StepMemoryIncrease")
|
|
|
MaxMemoryUsage := req.PostForm.Get("MaxMemoryUsage")
|
|
|
MaxConnection := req.PostForm.Get("MaxConnection")
|
|
|
MaxEviIncreased := req.PostForm.Get("MaxEviIncreased")
|
|
@@ -124,63 +120,51 @@ func syscfg_redis_set(resp http.ResponseWriter, req *http.Request) {
|
|
|
MailList := req.PostForm.Get("MailList")
|
|
|
Disabled := req.PostForm.Get("Disabled")
|
|
|
if Address == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 1, Error: "Redis服务地址不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(1, "Redis服务地址不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if Remark == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 2, Error: "Redis备注名称不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(2, "Redis备注名称不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MaxConnectWait == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 3, Error: "连接超时时长不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(3, "连接超时时长不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MaxStatusFailed == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 4, Error: "最大状态检测失败次数不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(4, "最大状态检测失败次数不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MinMemoryFree == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 5, Error: "最小可用内存空间不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(5, "最小可用内存空间不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
- if MinMemoryFreePC == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 6, Error: "最小可用内存空间百分比不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ if StepMemoryIncrease == "" {
|
|
|
+ resp.Write(ERROR_RET(6, "单次扩容大小不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MaxMemoryUsage == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 7, Error: "最大可用内存空间不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(7, "最大可用内存空间不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MaxConnection == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 8, Error: "最大并发连接数不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(8, "最大并发连接数不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MaxEviIncreased == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 9, Error: "最大新增淘汰记录数不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(9, "最大新增淘汰记录数不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MaxQPS == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 10, Error: "最大QPS值不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(10, "最大QPS值不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if MailList == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 11, Error: "报警邮件接收邮箱列表不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(11, "报警邮件接收邮箱列表不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
if Disabled == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 12, Error: "状态不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(12, "状态不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
IdInt, err := strconv.Atoi(Id)
|
|
@@ -189,98 +173,86 @@ func syscfg_redis_set(resp http.ResponseWriter, req *http.Request) {
|
|
|
}
|
|
|
MaxConnectWaitInt, err := strconv.Atoi(MaxConnectWait)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 13, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(13, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
MaxStatusFailedInt, err := strconv.Atoi(MaxStatusFailed)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 14, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(14, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
MinMemoryFreeInt, err := strconv.Atoi(MinMemoryFree)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 15, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(15, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
- MinMemoryFreePCInt, err := strconv.Atoi(MinMemoryFreePC)
|
|
|
+ StepMemoryIncreaseInt, err := strconv.Atoi(StepMemoryIncrease)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 16, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(16, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
MaxMemoryUsageInt, err := strconv.Atoi(MaxMemoryUsage)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 17, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(17, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
MaxConnectionInt, err := strconv.Atoi(MaxConnection)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 18, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(18, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
MaxEviIncreasedInt, err := strconv.Atoi(MaxEviIncreased)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 19, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(19, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
MaxQPSInt, err := strconv.Atoi(MaxQPS)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 20, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(20, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
DisabledInt, err := strconv.Atoi(Disabled)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 21, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(21, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
newRow := model.RedisCfgRow{
|
|
|
- Id: int64(IdInt),
|
|
|
- Address: Address,
|
|
|
- Remark: Remark,
|
|
|
- Password: Password,
|
|
|
- MaxConnectWait: int64(MaxConnectWaitInt),
|
|
|
- MaxStatusFailed: int64(MaxStatusFailedInt),
|
|
|
- MinMemoryFree: int64(MinMemoryFreeInt),
|
|
|
- MinMemoryFreePC: int64(MinMemoryFreePCInt),
|
|
|
- MaxMemoryUsage: int64(MaxMemoryUsageInt),
|
|
|
- MaxConnection: int64(MaxConnectionInt),
|
|
|
- MaxEviIncreased: int64(MaxEviIncreasedInt),
|
|
|
- MaxQPS: int64(MaxQPSInt),
|
|
|
- MailList: MailList,
|
|
|
- Disabled: DisabledInt != 0,
|
|
|
+ Id: int64(IdInt),
|
|
|
+ Address: Address,
|
|
|
+ Remark: Remark,
|
|
|
+ Password: Password,
|
|
|
+ MaxConnectWait: int64(MaxConnectWaitInt),
|
|
|
+ MaxStatusFailed: int64(MaxStatusFailedInt),
|
|
|
+ MinMemoryFree: int64(MinMemoryFreeInt),
|
|
|
+ StepMemoryIncrease: int64(StepMemoryIncreaseInt),
|
|
|
+ MaxMemoryUsage: int64(MaxMemoryUsageInt),
|
|
|
+ MaxConnection: int64(MaxConnectionInt),
|
|
|
+ MaxEviIncreased: int64(MaxEviIncreasedInt),
|
|
|
+ MaxQPS: int64(MaxQPSInt),
|
|
|
+ MailList: MailList,
|
|
|
+ Disabled: DisabledInt != 0,
|
|
|
}
|
|
|
mdlRedisCfg := model.NewRedisCfg(Db)
|
|
|
if IdInt > 0 {
|
|
|
affected, err := mdlRedisCfg.Update(&newRow)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 22, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(22, err.Error()))
|
|
|
} else if affected > 0 {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 0, Error: ""})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(0, ""))
|
|
|
} else {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 23, Error: "更新失败!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(23, "更新失败!"))
|
|
|
}
|
|
|
} else {
|
|
|
newRowId, err := mdlRedisCfg.Insert(&newRow)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 22, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ ret, _ := json.Marshal(ErrorRet{Errno: 22, Error: err.Error()})
|
|
|
+ resp.Write(ret)
|
|
|
+ resp.Write(ERROR_RET(22, err.Error()))
|
|
|
} else if newRowId > 0 {
|
|
|
- json, _ := json.Marshal(SyscfgRedisAddRet{Errno: 0, Error: "", Data: newRowId})
|
|
|
- resp.Write(json)
|
|
|
+ ret, _ := json.Marshal(SyscfgRedisAddRet{Errno: 0, Error: "", Data: newRowId})
|
|
|
+ resp.Write(ret)
|
|
|
} else {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 23, Error: "新增失败!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(23, "新增失败!"))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -293,26 +265,21 @@ func syscfg_redis_del(resp http.ResponseWriter, req *http.Request) {
|
|
|
req.ParseForm()
|
|
|
idStr := req.Form.Get("id")
|
|
|
if idStr == "" {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 1, Error: "ID不能为空!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(1, "ID不能为空!"))
|
|
|
return
|
|
|
}
|
|
|
id, err := strconv.Atoi(idStr)
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 2, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(2, err.Error()))
|
|
|
return
|
|
|
}
|
|
|
mdlRedisCfg := model.NewRedisCfg(Db)
|
|
|
affected, err := mdlRedisCfg.Delete(int64(id))
|
|
|
if err != nil {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 3, Error: err.Error()})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(3, err.Error()))
|
|
|
} else if affected > 0 {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 0, Error: ""})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(0, ""))
|
|
|
} else {
|
|
|
- json, _ := json.Marshal(ErrorRet{Errno: 4, Error: "操作失败!"})
|
|
|
- resp.Write(json)
|
|
|
+ resp.Write(ERROR_RET(4, "操作失败!"))
|
|
|
}
|
|
|
}
|