- 修复: WebSocket OnlineUserMap 加锁, aliasCronMap 改用 sync.Map - 修复: 替换 dgrijalva/jwt-go 为 golang-jwt/jwt (CVE) - 修复: CronJob.Add 缺少 return, resp.ErrorResp 未处理 error 类型 - 修复: token_util 和 login_service 越界访问 - 修复: Logger 级别配置被代码覆盖 - 修复: SysConfig.ConfigValue 字段长度 varchar(1) -> varchar(500) - 修复: Excel 导出列超过26列崩溃 - 修复: 数据库连接池配置过大, Ping goroutine 泄漏 - 修复: config_dao init 绕过缓存层 - 修复: Redis 空值导致 JSON 解析 panic - 修复: 分配角色页面只返回用户已有角色, 未返回所有角色 - 修复: 用户列表因角色关联导致重复行 - 移除: 前端硬编码私钥和默认密码 - 修复: LoginBody 和 updateAuthRole 路径
106 lines
2.0 KiB
Go
106 lines
2.0 KiB
Go
package resp
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
// Response 数据返回结构体
|
|
type Response struct {
|
|
Status int `json:"status"` // 返回状态值
|
|
Msg string `json:"msg"` // 返回的提示语
|
|
Data interface{} `json:"data"` // 返回数据
|
|
}
|
|
|
|
// Success 正确返回
|
|
func Success(data interface{}, msg ...string) *Response {
|
|
response := Response{
|
|
Status: http.StatusOK,
|
|
Data: data,
|
|
Msg: "操作成功",
|
|
}
|
|
if len(msg) > 0 {
|
|
response.Msg = msg[0]
|
|
}
|
|
return &response
|
|
}
|
|
|
|
// ErrorResp 错误返回
|
|
func ErrorResp(data ...interface{}) *Response {
|
|
response := Response{
|
|
Status: http.StatusInternalServerError,
|
|
Msg: "操作失败",
|
|
Data: nil,
|
|
}
|
|
for _, value := range data {
|
|
switch v := value.(type) {
|
|
case string:
|
|
response.Msg = v
|
|
case int:
|
|
response.Status = v
|
|
case error:
|
|
response.Msg = v.Error()
|
|
default:
|
|
response.Data = v
|
|
}
|
|
}
|
|
return &response
|
|
}
|
|
|
|
func Error(c *gin.Context, data ...interface{}) {
|
|
response := Response{
|
|
Status: http.StatusInternalServerError,
|
|
Msg: "操作失败",
|
|
Data: nil,
|
|
}
|
|
for _, value := range data {
|
|
switch v := value.(type) {
|
|
case string:
|
|
response.Msg = v
|
|
case int:
|
|
response.Status = v
|
|
case error:
|
|
response.Msg = v.Error()
|
|
default:
|
|
response.Data = v
|
|
}
|
|
}
|
|
c.JSON(http.StatusOK, response)
|
|
}
|
|
func ParamError(c *gin.Context, data ...interface{}) {
|
|
response := Response{
|
|
Status: http.StatusInternalServerError,
|
|
Msg: "参数绑定异常",
|
|
Data: nil,
|
|
}
|
|
for _, value := range data {
|
|
switch v := value.(type) {
|
|
case string:
|
|
response.Msg = v
|
|
case int:
|
|
response.Status = v
|
|
case error:
|
|
response.Msg = v.Error()
|
|
default:
|
|
response.Data = v
|
|
}
|
|
}
|
|
c.JSON(http.StatusBadRequest, response)
|
|
}
|
|
func OK(c *gin.Context, data ...interface{}) {
|
|
response := Response{
|
|
Status: http.StatusOK,
|
|
Msg: "操作成功",
|
|
Data: nil,
|
|
}
|
|
for _, datum := range data {
|
|
switch v := datum.(type) {
|
|
case string:
|
|
response.Msg = v
|
|
default:
|
|
response.Data = v
|
|
}
|
|
}
|
|
c.JSON(http.StatusOK, response)
|
|
}
|