21 lines
396 B
Go
21 lines
396 B
Go
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,
|
|
}
|
|
}
|