Documentation
¶
Overview ¶
Package mirror 在多个目标等价的下载源之间选择并轮换。
Index ¶
- Variables
- type Attempt
- type AttemptFunc
- type AttemptOutcome
- type AttemptReport
- type Catalog
- type DownloadFailure
- type DownloadProgress
- type DownloadRequest
- type DownloadResult
- type Downloader
- type DownloaderOption
- type FailureKind
- type IntegrityExhaustedError
- type Kind
- type OutcomeKind
- type PackageIndexRewrite
- type PackageIndexSpec
- type Plan
- type Policy
- type PolicySpec
- type ProgressFunc
- type Reporter
- type RotationError
- type RotationOption
- type RotationResult
- type Rotator
- type Source
- type Target
- type TargetSpec
- type WaitFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidRotationOption = errors.New( "mirror rotation option is invalid", ) ErrInvalidRotationRequest = errors.New( "mirror rotation request is invalid", ) )
var ErrInvalidDownloaderOption = errors.New("downloader option is invalid")
ErrInvalidDownloaderOption 表示 Downloader option 或私有依赖无效。
var ErrPolicyRejected = errors.New("mirror policy selection is rejected")
ErrPolicyRejected 表示合法 Policy 与当前 Catalog 的选择约束冲突。 调用方可把它映射为参数错误;Catalog 自身损坏不匹配此错误。
Functions ¶
This section is empty.
Types ¶
type AttemptFunc ¶
type AttemptFunc func( ctx context.Context, attempt Attempt, ) AttemptOutcome
AttemptFunc 对一个 Source 与原始 Target 执行一次调用方操作。
type AttemptOutcome ¶
type AttemptOutcome struct {
Kind OutcomeKind
FailureKind FailureKind
ActualCommit string
Err error
}
AttemptOutcome 是 AttemptFunc 返回的结构化结果。
type AttemptReport ¶
type AttemptReport struct {
Kind Kind
SourceKey string
SourceTry int
GlobalTry int
Target Target
TargetHash string
StartedAt time.Time
Duration time.Duration
Outcome OutcomeKind
FailureKind FailureKind
Error string
ActualCommit string
}
AttemptReport 保存一次实际 Attempt 的稳定诊断字段。
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog 保存按 Kind 分组的不可变有序 Source。
func DefaultCatalog ¶
DefaultCatalog 通过生产校验路径构造冻结的内置 Source。
func NewCatalog ¶
NewCatalog 校验并防御性复制完整的四类 Source。
type DownloadFailure ¶
type DownloadFailure struct {
Kind FailureKind
StatusCode int
Published bool
Err error
CleanupErr error
}
DownloadFailure 保存稳定分类、发布事实以及主错误和清理错误链。
func (*DownloadFailure) Error ¶
func (e *DownloadFailure) Error() string
Error 返回不含 URL 或外部错误原文的稳定文本。
func (*DownloadFailure) Unwrap ¶
func (e *DownloadFailure) Unwrap() []error
Unwrap 按主错误、清理错误的顺序保留完整类型链。
type DownloadProgress ¶
DownloadProgress 描述已确认完整写入并纳入摘要的字节进度。
type DownloadRequest ¶
type DownloadRequest struct {
URL string
FileName string
ExpectedSize int64
AllowUnknownSize bool
MaxSize int64
ExpectedSHA256 string
Progress ProgressFunc
}
DownloadRequest 描述单次下载已冻结的 URL、文件身份和完整性预期。
type DownloadResult ¶
DownloadResult 描述已发布或已发生发布事实的制品。
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader 执行一个已确定资源的一次流式 HTTPS 下载。
func NewDownloader ¶
func NewDownloader( layout *config.Layout, options ...DownloaderOption, ) (*Downloader, error)
NewDownloader 创建构造后只读、可并发调用的 Downloader。
func (*Downloader) Download ¶
func (d *Downloader) Download( ctx context.Context, request DownloadRequest, ) (DownloadResult, error)
Download 执行一次已确定资源的 HTTPS 传输、校验和 no-replace 发布。
type DownloaderOption ¶
type DownloaderOption func(*downloaderOptions) error
DownloaderOption 配置 Downloader 的有限时间参数。
func WithDownloaderProgressInterval ¶
func WithDownloaderProgressInterval(interval time.Duration) DownloaderOption
WithDownloaderProgressInterval 设置非终点进度的最小报告间隔。
func WithDownloaderTimeouts ¶
func WithDownloaderTimeouts( connectTimeout time.Duration, readTimeout time.Duration, ) DownloaderOption
WithDownloaderTimeouts 设置连接阶段与读取空闲超时。
type FailureKind ¶
type FailureKind string
FailureKind 是不参与状态迁移的开放诊断标识。
const ( // FailureInvalidRequest 表示下载请求的固定字段无效。 FailureInvalidRequest FailureKind = "invalid_request" // FailureURLPolicy 表示 URL 不符合绝对 HTTPS 策略。 FailureURLPolicy FailureKind = "url_policy" // FailureRedirectDowngrade 表示 HTTPS 重定向尝试降级为 HTTP。 FailureRedirectDowngrade FailureKind = "redirect_downgrade" // FailureConnectTimeout 表示请求在响应头返回前超时。 FailureConnectTimeout FailureKind = "connect_timeout" // FailureReadTimeout 表示响应体网络读取空闲超时。 FailureReadTimeout FailureKind = "read_timeout" // FailureNetwork 表示未细分的网络传输故障。 FailureNetwork FailureKind = "network" // FailureHTTPStatus 表示响应状态不是 200。 FailureHTTPStatus FailureKind = "http_status" // FailureSizeMismatch 表示制品大小与预期不一致。 FailureSizeMismatch FailureKind = "size_mismatch" // FailureChecksumMismatch 表示制品摘要与预期不一致。 FailureChecksumMismatch FailureKind = "checksum_mismatch" // FailureCancelled 表示调用方取消了下载。 FailureCancelled FailureKind = "cancelled" // FailureProgress 表示同步进度回调失败。 FailureProgress FailureKind = "progress" // FailureDestinationOccupied 表示最终目标已被其他对象占用。 FailureDestinationOccupied FailureKind = "destination_occupied" // FailureFilesystem 表示本地文件会话操作失败。 FailureFilesystem FailureKind = "filesystem" )
func (FailureKind) Valid ¶
func (k FailureKind) Valid() bool
Valid 报告 FailureKind 是否满足开放的安全 snake_case 语法。
type IntegrityExhaustedError ¶
type IntegrityExhaustedError struct {
// contains filtered or unexported fields
}
IntegrityExhaustedError 表示自然耗尽中至少发生一次完整性失败。
func (*IntegrityExhaustedError) Error ¶
func (e *IntegrityExhaustedError) Error() string
Error 返回不包含 Source URL 或底层错误文本的稳定诊断。
func (*IntegrityExhaustedError) Reports ¶
func (e *IntegrityExhaustedError) Reports() []AttemptReport
Reports 返回有序 AttemptReport 的防御性副本。
func (*IntegrityExhaustedError) Unwrap ¶
func (e *IntegrityExhaustedError) Unwrap() []error
Unwrap 返回底层错误链的防御性副本。
type OutcomeKind ¶
type OutcomeKind string
OutcomeKind 是 AttemptFunc 返回的结构化状态转换。
const ( OutcomeSucceeded OutcomeKind = "succeeded" OutcomeRetrySameSource OutcomeKind = "retry_same_source" OutcomeSwitchSource OutcomeKind = "switch_source" OutcomeIntegrityFailure OutcomeKind = "integrity_failure" OutcomeTargetFailure OutcomeKind = "target_failure" OutcomeCancelled OutcomeKind = "cancelled" )
type PackageIndexRewrite ¶
type PackageIndexRewrite struct {
// contains filtered or unexported fields
}
PackageIndexRewrite 保存包索引源在锁文件 URL 改写中使用的两个前缀。
两个前缀由目录显式声明,不从 BaseURL 推导:官方源的 artifact 位于 files.pythonhosted.org,与它的索引不同 host,任何「去掉结尾 simple/」 一类的推导都会得到不存在的地址;三家镜像索引与 artifact 同 host 只是巧合。
func (PackageIndexRewrite) PackagesBase ¶
func (r PackageIndexRewrite) PackagesBase() string
PackagesBase 返回替换 https://files.pythonhosted.org/packages/ 的前缀,以 / 结尾。
func (PackageIndexRewrite) SimpleBase ¶
func (r PackageIndexRewrite) SimpleBase() string
SimpleBase 返回替换 https://pypi.org/simple 的前缀,不以 / 结尾。
type PackageIndexSpec ¶
type PackageIndexSpec struct {
Key string
BaseURL string
SimpleBase string
PackagesBase string
Official bool
}
PackageIndexSpec 是带显式锁改写前缀的包索引源构造输入。
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
Plan 是单次操作的不可变 Source 顺序快照。
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy 保存不可变的已解析镜像策略。
type PolicySpec ¶
PolicySpec 是 CLI 已解析镜像策略的构造输入。
type ProgressFunc ¶
type ProgressFunc func(progress DownloadProgress) error
ProgressFunc 同步接收单调下载进度。
type Reporter ¶
type Reporter interface {
ReportAttempt(ctx context.Context, report AttemptReport) error
}
Reporter 同步持久化一次已冻结的 AttemptReport。 有状态实现会被同一 Rotator 的并发 Run 调用,必须自行保证并发安全。
type RotationError ¶
type RotationError struct {
// contains filtered or unexported fields
}
RotationError 表示离线或全部普通 Source 自然耗尽。
func (*RotationError) Error ¶
func (e *RotationError) Error() string
Error 返回不包含 Source URL 或底层错误文本的稳定诊断。
func (*RotationError) Reports ¶
func (e *RotationError) Reports() []AttemptReport
Reports 返回有序 AttemptReport 的防御性副本。
type RotationOption ¶
type RotationOption func(*rotationOptions) error
RotationOption 配置构造后只读的 Rotator。
func WithAttemptReporter ¶
func WithAttemptReporter(reporter Reporter) RotationOption
WithAttemptReporter 注入同步 AttemptReport 接收方。
func WithMaxSourceAttempts ¶
func WithMaxSourceAttempts(attempts int) RotationOption
WithMaxSourceAttempts 配置每个 Source 的有限总尝试次数。
func WithRetryDelay ¶
func WithRetryDelay(delay time.Duration) RotationOption
WithRetryDelay 配置同源重试前的正等待时长。
func WithRotatorClock ¶
func WithRotatorClock(clock func() time.Time) RotationOption
WithRotatorClock 注入报告计时使用的时钟。
type RotationResult ¶
type RotationResult struct {
Source Source
ActualCommit string
Reports []AttemptReport
}
RotationResult 保存成功源、Git 实际 Commit 和有序报告。
type Rotator ¶
type Rotator struct {
// contains filtered or unexported fields
}
Rotator 保存不可变的轮换依赖与有限重试参数。 同一 Rotator 可被多个 goroutine 并发调用 Run。
func NewRotator ¶
func NewRotator(options ...RotationOption) (*Rotator, error)
NewRotator 使用生产报告 context factory 构造只读 Rotator。
func (*Rotator) Run ¶
func (r *Rotator) Run( ctx context.Context, plan Plan, target Target, attempt AttemptFunc, ) (RotationResult, error)
Run 按 Plan 顺序执行有限尝试并保持 Target 不变。
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source 是经过校验的不可变 HTTPS 网络源。
simpleBase 与 packagesBase 只对 KindPackageIndex 有意义,且只能由 NewPackageIndexSource 显式赋值,经 PackageIndexRewrite 读取。
func NewPackageIndexSource ¶
func NewPackageIndexSource(spec PackageIndexSpec) (Source, error)
NewPackageIndexSource 校验并构造带显式改写前缀的包索引源。
func (Source) PackageIndexRewrite ¶
func (s Source) PackageIndexRewrite() (PackageIndexRewrite, bool)
PackageIndexRewrite 返回包索引源的锁改写前缀;未显式声明时报告 false。
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Target 保存跨 Source 尝试不可改变的目标字段。
func (Target) ValidateForKind ¶
ValidateForKind 校验 kind 执行所需字段与额外关系。