updater

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Copyright (c) 2026 Lingying. SPDX-License-Identifier: MIT Updater — 带重试、Range 续传与停滞检测的下载器。

Copyright (c) 2026 Lingying. SPDX-License-Identifier: MIT Updater — 候选下载源与 Release 资产 URL 拼装。

Copyright (c) 2026 Lingying. SPDX-License-Identifier: MIT Self-update: resolve the latest release, download it, replace this binary.

The update path is deliberately identical for every install method. Whether ly arrived via install.sh or go install, we download the GitHub Release archive for this platform and overwrite the running executable in place.

Index

Constants

View Source
const GitHubBase = "https://github.com"

GitHubBase 是所有下载地址的根。公共代理的用法是把完整的 GitHub URL 接在自己 后面,因此代理源的 Base 形如 "https://ghfast.top/https://github.com"。

Variables

This section is empty.

Functions

This section is empty.

Types

type Applied

type Applied struct {
	SourceName string
	// ChecksumTrusted 为 false 表示校验和取自镜像,只能防传输损坏、不能防篡改。
	// 调用方必须就此向用户告警。
	ChecksumTrusted bool
}

Applied 描述一次成功更新的来源信息。

type Source

type Source struct {
	Name    string
	Base    string
	Trusted bool
}

Source 是一个候选下载来源。 Trusted 标记该来源是否可信——只有可信来源取回的校验和才能防篡改。

func Sources

func Sources() []Source

Sources 按优先级返回候选源:直连优先,其后是 LY_MIRROR 指定的镜像, 最后是内置公共代理。公共代理只作回退,随时可能失效。

func (Source) AssetURL

func (s Source) AssetURL(repo, version, asset string) string

AssetURL 拼出某个 Release 资产的下载地址。version 为空表示取最新。

func (Source) LatestTagURL

func (s Source) LatestTagURL(repo string) string

LatestTagURL 指向 releases/latest。该地址返回 302,Location 形如 .../releases/tag/v0.1.5——一次请求即可拿到版本号,无需 api.github.com。

type Updater

type Updater struct {
	Current  string
	ExecPath string
	HTTP     *http.Client
	Repo     string
	Sources  []Source
	GOOS     string
	GOARCH   string
}

Updater holds everything the update flow needs. Repo, Sources and the platform fields are configurable so tests can point at a local server.

func New

func New(current string) (*Updater, error)

New resolves the running executable — following symlinks so that a ~/.local/bin/ly symlink updates the real file, not the link.

func (*Updater) Apply

func (u *Updater) Apply(ctx context.Context, version string) (Applied, error)

Apply downloads the release archive for `version`, verifies its SHA-256 against checksums.txt, and replaces the running executable with it.

func (*Updater) LatestVersion

func (u *Updater) LatestVersion(ctx context.Context) (string, error)

LatestVersion 读取 releases/latest 的 302 跳转目标。该地址的 Location 形如 .../releases/tag/v0.1.6,一次请求即可拿到版本号——既不需要 raw.githubusercontent.com 上的清单,也不需要 api.github.com。

func (*Updater) NeedsUpdate

func (u *Updater) NeedsUpdate(latest string) bool

NeedsUpdate reports whether latest is worth installing over the running build. A dev build has no comparable version, so it always updates.

Jump to

Keyboard shortcuts

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