Documentation
¶
Overview ¶
Package update contains installation-source detection and update domain logic.
Index ¶
- func CleanupPendingWindowsUpdate() error
- func NewReleaseHTTPClient(proxyURL string) (*http.Client, error)
- type AutomaticUpdateChecker
- type AutomaticUpdateCheckerOptions
- type AutomaticUpdateNotice
- type AutomaticUpdateRequest
- type Command
- type CommandRunner
- type GitHubReleaseClient
- type InstallSource
- type Release
- type ReleaseAsset
- type ReleaseBinaryChecker
- type ReleaseCheckOptions
- type ReleaseCheckResult
- type ReleaseChecker
- type ReleaseClientOptions
- type ReleaseFileReplacer
- type ReleaseInstaller
- type ReleaseInstallerOptions
- type SourceDetector
- type SourceDetectorFunc
- type UpdateCoordinator
- type UpdateCoordinatorOptions
- type UpdateRequest
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupPendingWindowsUpdate ¶
func CleanupPendingWindowsUpdate() error
CleanupPendingWindowsUpdate 删除 ReplaceFileW 留下的旧可执行文件。非 Windows 不创建 该备份,因此没有任何文件操作;调用方应在启动 CLI 前调用并把失败展示给用户。
Types ¶
type AutomaticUpdateChecker ¶
type AutomaticUpdateChecker struct {
// contains filtered or unexported fields
}
AutomaticUpdateChecker 在普通 CLI 命令成功后判断是否应提示稳定版更新。
func NewAutomaticUpdateChecker ¶
func NewAutomaticUpdateChecker(options AutomaticUpdateCheckerOptions) (*AutomaticUpdateChecker, error)
NewAutomaticUpdateChecker 建立自动更新检查器。
func (*AutomaticUpdateChecker) Check ¶
func (c *AutomaticUpdateChecker) Check(ctx context.Context, request AutomaticUpdateRequest) (*AutomaticUpdateNotice, error)
Check 查询稳定版更新,并仅在较新版本存在时返回提示。 开发构建没有发布渠道,必须在读取本机安装来源或访问网络前返回。
type AutomaticUpdateCheckerOptions ¶
type AutomaticUpdateCheckerOptions struct {
SourceDetector SourceDetector
ReleaseChecker ReleaseChecker
}
AutomaticUpdateCheckerOptions 注入自动检查所需的只读依赖。 自动检查不执行安装命令,也不接触 Release 资产。
type AutomaticUpdateNotice ¶
type AutomaticUpdateNotice struct {
Source InstallSource
CurrentVersion string
LatestVersion string
UpdateCommand string
}
AutomaticUpdateNotice 是 CLI 可安全展示的更新提示。 UpdateCommand 是安装来源对应的准确后续命令,不会在检查阶段执行。
type AutomaticUpdateRequest ¶
AutomaticUpdateRequest 描述当前二进制的构建信息。
type CommandRunner ¶
CommandRunner 执行 Homebrew 或 Go 的更新命令。
func NewCommandRunner ¶
func NewCommandRunner(out, errOut io.Writer) CommandRunner
NewCommandRunner 建立把子进程输出直连到 CLI 输出流的无 shell 命令执行器。
type GitHubReleaseClient ¶
type GitHubReleaseClient struct {
// contains filtered or unexported fields
}
GitHubReleaseClient 通过 GitHub Releases API 查询候选版本。
func NewGitHubReleaseClient ¶
func NewGitHubReleaseClient(options ReleaseClientOptions) (*GitHubReleaseClient, error)
NewGitHubReleaseClient 建立唯一使用 GitHub Releases API 的更新查询客户端。
func (*GitHubReleaseClient) Check ¶
func (c *GitHubReleaseClient) Check(ctx context.Context, options ReleaseCheckOptions) (ReleaseCheckResult, error)
Check 从 GitHub Releases API 选择符合渠道的最高 SemVer Release。
type InstallSource ¶
type InstallSource string
InstallSource 表示当前二进制可由哪个安装渠道更新。
const ( InstallSourceDevelopment InstallSource = "development" InstallSourceHomebrewStable InstallSource = "homebrew-stable" InstallSourceHomebrewBeta InstallSource = "homebrew-beta" InstallSourceGoInstall InstallSource = "go-install" InstallSourceRelease InstallSource = "release" )
func DetectInstallSource ¶
func DetectInstallSource(info buildinfo.Info) (InstallSource, error)
DetectInstallSource 根据构建信息和当前可执行文件识别安装来源。
type Release ¶
type Release struct {
TagName string
Version string
Prerelease bool
Assets []ReleaseAsset
}
Release 是可用于更新的 GitHub Release 的最小公开描述。
type ReleaseAsset ¶
type ReleaseAsset struct {
Name string `json:"name"`
DownloadURL string `json:"browser_download_url"`
}
ReleaseAsset 是 GitHub Release 附带的一个可下载资产。 仅使用 Releases API 返回的 browser_download_url,避免根据 tag 猜测下载地址。
type ReleaseBinaryChecker ¶
ReleaseBinaryChecker 在替换前验证下载二进制实际报告的版本。 实现必须只在 archive、checksum 和签名都已通过后调用二进制。
type ReleaseCheckOptions ¶
ReleaseCheckOptions 表示一次 Releases 查询的渠道与触发方式。
type ReleaseCheckResult ¶
ReleaseCheckResult 是一次查询得到的候选 Release。
type ReleaseChecker ¶
type ReleaseChecker interface {
Check(context.Context, ReleaseCheckOptions) (ReleaseCheckResult, error)
}
ReleaseChecker 查询某个更新渠道可用的 GitHub Release。
type ReleaseClientOptions ¶
type ReleaseClientOptions struct {
APIBaseURL string
Repository string
HTTPClient *http.Client
CacheDir string
Now func() time.Time
}
ReleaseClientOptions 配置 GitHub Releases 客户端。 APIBaseURL、HTTPClient、CacheDir 和 Now 允许调用方为受控环境注入依赖。
type ReleaseFileReplacer ¶
ReleaseFileReplacer 抽象最终的同目录原子替换,供受控测试和平台实现复用。
type ReleaseInstaller ¶
ReleaseInstaller 安装已核验的 Release。
func NewReleaseInstaller ¶
func NewReleaseInstaller(options ReleaseInstallerOptions) ReleaseInstaller
NewReleaseInstaller 建立 Release 自更新器。未配置 trusted key 时仍返回实例, 这样 --check 不受影响;真正安装会明确报出缺少信任根,而不是假装更新成功。
type ReleaseInstallerOptions ¶
type ReleaseInstallerOptions struct {
HTTPClient *http.Client
TrustedKeys map[string]ed25519.PublicKey
ExecutablePath func() (string, error)
GOOS string
GOARCH string
BinaryChecker ReleaseBinaryChecker
Replacer ReleaseFileReplacer
}
ReleaseInstallerOptions 允许生产组装与受控测试分别注入信任根和系统依赖。 TrustedKeys 只允许 Ed25519 公钥;私钥绝不能进入生产组装或此 API。
type SourceDetector ¶
type SourceDetector interface {
Detect(buildinfo.Info) (InstallSource, error)
}
SourceDetector 识别当前可执行文件的安装渠道。
type SourceDetectorFunc ¶
type SourceDetectorFunc func(buildinfo.Info) (InstallSource, error)
SourceDetectorFunc 让函数可以作为 SourceDetector 使用。
func (SourceDetectorFunc) Detect ¶
func (f SourceDetectorFunc) Detect(info buildinfo.Info) (InstallSource, error)
Detect 调用底层函数。
type UpdateCoordinator ¶
type UpdateCoordinator struct {
// contains filtered or unexported fields
}
UpdateCoordinator 按安装渠道编排显式更新,不负责下载资产细节。
func NewUpdateCoordinator ¶
func NewUpdateCoordinator(options UpdateCoordinatorOptions) (*UpdateCoordinator, error)
NewUpdateCoordinator 建立可测试的更新策略编排器。
func (*UpdateCoordinator) Execute ¶
func (c *UpdateCoordinator) Execute(ctx context.Context, request UpdateRequest) (UpdateResult, error)
Execute 查询更新并在非 check 模式下执行来源对应的更新策略。
type UpdateCoordinatorOptions ¶
type UpdateCoordinatorOptions struct {
SourceDetector SourceDetector
ReleaseChecker ReleaseChecker
CommandRunner CommandRunner
ReleaseInstaller ReleaseInstaller
}
UpdateCoordinatorOptions 注入更新策略需要的外部依赖,供 CLI 和受控测试复用。
type UpdateRequest ¶
UpdateRequest 描述一次显式 update 命令的用户选择。
type UpdateResult ¶
type UpdateResult struct {
Source InstallSource `json:"source"`
CurrentVersion string `json:"current_version"`
LatestVersion *string `json:"latest_version"`
LatestPrerelease bool `json:"latest_prerelease"`
UpdateAvailable bool `json:"update_available"`
}
UpdateResult 是检查或执行更新后可安全展示的状态。