123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package result
- type Result struct {
- Code int32 `json:"code"`
- Msg string `json:"msg"`
- Data interface{} `json:"data"`
- }
- func (errcode *Result) Error() string {
- return errcode.Msg
- }
- func NewResult(Code int32, Msg string, Data interface{}) *Result {
- return &Result{Code, Msg, Data}
- }
- func SuccessResult(Data interface{}) *Result {
- return &Result{2000, "操作成功", Data}
- }
- func (r Result) SetMsg(msg string) *Result {
- r.Msg = msg
- return &r
- }
- func (r Result) SetData(data interface{}) *Result {
- r.Data = data
- return &r
- }
- type Page struct {
- Page int `json:"page" db:"page"`
- Size int `json:"size,omitempty" db:"size,omitempty"`
- Total int `json:"total,omitempty" db:"total,omitempty"`
- Data interface{} `json:"data,omitempty" db:"data,omitempty"`
- }
- func NewPage(page, size, total int, data interface{}) *Page {
- return &Page{
- page,
- size,
- total,
- data,
- }
- }
- // ResultChange 影响行数
- type ResultChange struct {
- RowsAffected int64 `json:"rowsAffected"`
- RowsFailed int64 `json:"rowsFailed"`
- }
- func NewResultChange(row int64) ResultChange {
- return ResultChange{row, 0}
- }
- var (
- SUCCESS = NewResult(2000, "操作成功", nil)
- UNAUTHORIZED = NewResult(4001, "未授权", nil)
- FORMATE_ERROR = NewResult(4002, "格式转换异常", nil)
- NO_PERMISSION = NewResult(4003, "无权限", nil)
- DATA_NOT_FOUND = NewResult(4004, "不存在该数据", nil)
- DATA_NO_CHANGE = NewResult(4005, "数据未发生改变", nil)
- PASSWORD_ERROR = NewResult(4006, "密码错误", nil)
- PARAM_ERROR = NewResult(4007, "参数错误", nil)
- USER_IS_EXISTED = NewResult(4008, "用户已存在", nil)
- USER_IS_NOT_EXISTED = NewResult(4009, "用户不存在", nil)
- USER_PENDING_REVIEW = NewResult(4010, "用户待审核", nil)
- ROLE_IS_NOT_EXISTED = NewResult(4011, "角色不存在", nil)
- UNKNOW_ERROR = NewResult(5000, "未知异常", nil)
- )
|