package say import ( "fmt" "github.com/labstack/echo/v4" ) // 统一返回格式 type Reply struct { Errcode int `json:"errcode"` Errmsg string `json:"errmsg,omitempty"` Data interface{} `json:"data,omitempty"` } var MSG = map[string]string{ "e10000": "系统繁忙,请稍后再试!", "e10001": "参数错误", "e10002": "验证码错误", "e10003": "用户创建失败", "e10004": "用户不存在", "e10005": "密码错误", "e10006": "角色获取失败", "e10007": "该值不可用,系统中已存在!", "e10008": "修改角色信息失败", "e10009": "删除角色信息失败", "e10010": "删除角色权限失败", "e10011": "角色绑定用户失败", "e10012": "角色授权菜单权限失败", "e10013": "用户名已存在", "e10014": "用户信息修改失败", "e10015": "删除用户失败", "e10016": "删除用户绑定角色信息失败", "e10017": "添加菜单失败", "e10018": "菜单信息获取失败", "e10019": "编辑菜单失败", "e10020": "删除菜单失败", "e10021": "创建角色失败", "e10022": "用户已经绑定角色", "e10023": "操作失败,请稍等后再试!", "e10024": "上级菜单不可以是自己!", "e10025": "旧密码验证失败", "e10026": "旧密码错误", "e10027": "添加代理失败", "e10028": "该用户不是代理", "e10029": "取消代理失败", "e10030": "代理获取失败", "e10031": "账户余额不足", "e10032": "提现信息获取失败", "e10033": "请勿重复审核", "e10034": "账户已冻结", "e10035": "账户已删除", "e10036": "请勿重复审核", "e10037": "请先申请收款方式", } func newReply(errcode int, data interface{}) (int, Reply) { if errcode == 0 { if data != nil { return 200, Reply{ Errcode: errcode, Errmsg: "操作成功!", Data: data, } } return 200, Reply{ Errcode: errcode, } } msg := MSG[fmt.Sprintf("e%d", errcode)] return 200, Reply{ Errcode: errcode, Errmsg: msg, } } func response(errcode int, data interface{}) (int, Reply) { return newReply(errcode, data) } func Success(c echo.Context, errcode int, data interface{}) error { return c.JSON(response(errcode, data)) }