添加文件: xy_sh/errors.go
This commit is contained in:
parent
c9f01792b2
commit
2afaf7d11a
|
|
@ -0,0 +1,19 @@
|
||||||
|
package xy_sh
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// Error 自定义错误类型,包含返回码和错误信息
|
||||||
|
type Error struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"msg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error 实现 error 接口
|
||||||
|
func (e *Error) Error() string {
|
||||||
|
return fmt.Sprintf("code=%d, msg=%s", e.Code, e.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSuccess 判断业务返回码是否表示成功
|
||||||
|
func IsSuccess(code int) bool {
|
||||||
|
return code == 0
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue