package global import ( "errors" "github.com/go-sql-driver/mysql" ) var ( GetFailedErr = errors.New("查询失败") CreateFailedErr = errors.New("添加失败") UpdateFailedErr = errors.New("更新失败") DeleteFailedErr = errors.New("删除失败") GetNotFoundErr = errors.New("数据不存在") GetNotFoundOrNoPermissionErr = errors.New("数据不存在或无权查看该数据") UpdateNotFoundOrNoPermissionErr = errors.New("数据不存在或无权修改该数据") DeleteNotFoundOrNoPermissionErr = errors.New("数据不存在或无权删除该数据") ) func IsUniqueIndexErr(err error) bool { uniqueErr := &mysql.MySQLError{} if ok := errors.As(err, &uniqueErr); ok { return uniqueErr.Number == 1062 } return false }