12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package common
- 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"
- )
- func SuccessResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeSucceed,
- Msg: msg,
- Data: data,
- }
- }
- func FailResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeInternal,
- Msg: msg,
- Data: data,
- }
- }
- func ParamsInvalidResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeParamsInvalid,
- Msg: msg,
- Data: data,
- }
- }
- func OperationInvalidResponse(msg string, data interface{}) *Errors {
- return &Errors{
- Code: CodeOperationInvalid,
- Msg: msg,
- Data: data,
- }
- }
- func NormalResponse(code int, msg string, data interface{}) *Errors {
- return &Errors{
- Code: code,
- Msg: msg,
- Data: data,
- }
- }
|