diff --git a/xy_sh/errors.go b/xy_sh/errors.go new file mode 100644 index 0000000..3128bd1 --- /dev/null +++ b/xy_sh/errors.go @@ -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 +} \ No newline at end of file