1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package util
- type Errors struct {
- Code int `json:"code"`
- Success bool `json:"success"`
- Msg string `json:"msg"`
- Data interface{} `json:"data"`
- }
- const (
- CodeSucceed = 200 //成功
- CodeInternal = 9999 //内部错误
- CodeParamsInvalid = 10001 //非法参数
- CodeOperationInvalid = 10002 //非法操作
- )
- const (
- Succeeded = "操作成功"
- Success = "success"
- Failed = "操作失败"
- Fail = "fail"
- )
- func SuccessResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeSucceed,
- Success: true,
- Msg: msg,
- Data: data,
- }
- }
- func FailResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeInternal,
- Success: false,
- Msg: msg,
- Data: data,
- }
- }
- func ParamsInvalidResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeParamsInvalid,
- Success: false,
- Msg: msg,
- Data: data,
- }
- }
- func OperationInvalidResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeOperationInvalid,
- Success: false,
- Msg: msg,
- Data: data,
- }
- }
- func NormalResponse(code int, msg string, data interface{}) *Errors {
- return &Errors{
- Code: code,
- Success: true,
- Msg: msg,
- Data: data,
- }
- }
|