update

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package update contains installation-source detection and update domain logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupPendingWindowsUpdate

func CleanupPendingWindowsUpdate() error

CleanupPendingWindowsUpdate 删除 ReplaceFileW 留下的旧可执行文件。非 Windows 不创建 该备份,因此没有任何文件操作;调用方应在启动 CLI 前调用并把失败展示给用户。

func NewReleaseHTTPClient

func NewReleaseHTTPClient(proxyURL string) (*http.Client, error)

NewReleaseHTTPClient 建立只供更新查询使用的 HTTP client。 显式 update 的网络生命周期由调用方 context 控制,不能复用 Pixiv API 的固定超时。

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

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

type AutomaticUpdateRequest struct {
	BuildInfo buildinfo.Info
}

AutomaticUpdateRequest 描述当前二进制的构建信息。

type Command

type Command struct {
	Name string
	Args []string
}

Command 是无需 shell 解析的程序及其参数。

type CommandRunner

type CommandRunner interface {
	Run(context.Context, Command) error
}

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

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

type ReleaseBinaryChecker interface {
	Check(context.Context, string, string) error
}

ReleaseBinaryChecker 在替换前验证下载二进制实际报告的版本。 实现必须只在 archive、checksum 和签名都已通过后调用二进制。

type ReleaseCheckOptions

type ReleaseCheckOptions struct {
	IncludePrerelease bool
	Automatic         bool
}

ReleaseCheckOptions 表示一次 Releases 查询的渠道与触发方式。

type ReleaseCheckResult

type ReleaseCheckResult struct {
	Release   *Release
	Throttled bool
}

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

type ReleaseFileReplacer interface {
	Replace(string, string) error
}

ReleaseFileReplacer 抽象最终的同目录原子替换,供受控测试和平台实现复用。

type ReleaseInstaller

type ReleaseInstaller interface {
	Install(context.Context, Release) error
}

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

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

type UpdateRequest struct {
	BuildInfo         buildinfo.Info
	Check             bool
	IncludePrerelease bool
}

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 是检查或执行更新后可安全展示的状态。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL