zhangqian
2024-03-12 1a2e7a46273fdb6eb53348f4e06100aa7854c3cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package code
 
import "net/http"
 
// Code 错误输出数据结构
type Code struct {
    Status  int    `json:"status"` // HTTP 状态
    Message string `json:"msg"`    // 描述信息
}
 
// 实现 error 接口的 Error 方法
func (c *Code) Error() string {
    return c.Message
}
 
var (
    Success       = &Code{http.StatusOK, "请求处理成功"}
    UpdateSuccess = &Code{http.StatusOK, "更新成功"}
    DeleteSuccess = &Code{http.StatusOK, "删除成功"}
 
    SaveFail          = &Code{3001, "新增失败"}
    RequestParamError = &Code{3002, "请求参数有误"}
    DeleteUsingError  = &Code{3003, "删除失败"}
    NameExistedError  = &Code{3004, "名称已存在"}
    SelectError       = &Code{3013, "查询失败"}
 
    SilkRankStandardNotSetError = &Code{4101, "生丝标注未设定"}
)