Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
RepoOwner string // GitHub repo owner (required for GitHub source; unused for flat HTTP)
RepoName string // GitHub repo name (required for GitHub source; unused for flat HTTP)
UpdateURL string // "" = GitHub source; "https://..." = flat HTTP source
CachePath string // where to store update_cache.json (required)
Log *slog.Logger
}
Config configures New.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater checks for newer sshmng versions and applies them. The cache stores the last-checked version + timestamp to stay under GitHub's 60 req/hour unauthenticated rate limit. All methods are safe for concurrent use within a single process; cross-process coordination is NOT provided (cache TTL makes concurrent updates rare and non-corrupting — a lost write just means one extra source fetch).
func New ¶
New creates an Updater. Returns an error if the config is invalid (missing CachePath, missing repo owner/name for GitHub source, malformed UpdateURL for flat HTTP source).
func (*Updater) LatestVersion ¶
LatestVersion returns the latest released version tag (e.g., "v1.2.3"). Cache-aware: returns the cached value if fresh; otherwise queries the source and updates the cache. Read-only — never downloads or swaps the binary.
func (*Updater) UpdateFromFile ¶ added in v0.1.5
UpdateFromFile 用用户本地下载的 release asset 升级,绕过 GitHub API 限流。
用户用浏览器(带 GitHub 登录 session)下载 asset,比 unauthenticated API 稳得多。assetPath 支持三种输入(适配 Safari 自动解压行为,降低用户心智负担):
- .tar.gz:goreleaser 原始产出
- .tar:Safari 把 .tar.gz 剥掉 gzip 层后的产物
- 目录:Safari 进一步解压后的目录树(内含 sshmng 二进制)
不做 checksum 校验——用户自己下载的文件,信任源就是用户自己;Safari 解压后 hash 也对不上,强校验反而阻碍使用。平台校验仍做(文件名解析 goos/goarch, 目录输入跳过此检查)。
不检查版本新旧——用户显式指定文件,即使"降级"也执行(如回滚到旧版)。 dev 构建也允许(用户可能用本地构建的 release 包升级 dev 实例)。
返回从文件名解析出的版本 tag(目录输入返回空字符串)。
func (*Updater) UpdateToLatest ¶
UpdateToLatest checks for a newer version (cache-aware) and applies it if found. Returns the latest version seen and whether an update was applied. Already-up-to-date → (latest, false, nil). Dev build → error.