添加文件: xy_sh/errors.go

This commit is contained in:
renzhiyuan 2026-07-24 17:42:15 +08:00
parent c9f01792b2
commit 2afaf7d11a
1 changed files with 19 additions and 0 deletions

19
xy_sh/errors.go Normal file
View File

@ -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
}