This commit is contained in:
2024-10-12 20:41:55 +08:00
parent 8c09120db6
commit 597e4f1b89
75 changed files with 5009 additions and 823 deletions

9
pkg/errs/api.go Normal file
View File

@@ -0,0 +1,9 @@
package errs
// 常见错误
var (
ErrSystem = NewAppError(1001, "业务失败")
ErrParamDecryption = NewAppError(1002, "参数解密失败")
ErrParamValidation = NewAppError(1003, "校验参数不正确")
ErrDataSource = NewAppError(1004, "数据源异常")
)

20
pkg/errs/err.go Normal file
View File

@@ -0,0 +1,20 @@
package errs
// 定义自定义错误类型
type AppError struct {
Code int // 错误码
Message string // 错误信息
}
// 实现 error 接口的 Error 方法
func (e *AppError) Error() string {
return e.Message
}
// 创建带有错误码和错误信息的 AppError
func NewAppError(code int, message string) *AppError {
return &AppError{
Code: code,
Message: message,
}
}