Documentation
¶
Overview ¶
Package update implements anfra's self-update: discover the latest GitHub release, compare it to the compiled-in version, download the binary for this platform, and atomically replace the running executable.
Follows the common CLI pattern (gh, deno, bun): a manual `anfra update` command plus a cached, non-blocking "update available" notice. Fully-automatic update is opt-in (ANFRA_AUTO_UPDATE), never the default.
Index ¶
Constants ¶
const CheckEvery = checkTTL
CheckEvery is how often a long-running process should call Check: once the cache it reads has gone stale.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply downloads the platform asset and atomically replaces the running binary. If progress is non-nil, download progress is rendered to it (a single, in-place updated line); pass nil for a silent download (agents/CI).
func CachedNotice ¶
func CachedNotice() string
CachedNotice returns a one-line "update available" message from the cached check, or "" if none is available / the cache says we're current.
func Notice ¶
Notice is the one-line "update available" message for r, or "" when r is not newer than the running version.
func RecordCheck ¶
func RecordCheck(r *Release)
RecordCheck stores an already-fetched release in the cache (no network), so a foreground check refreshes the notice cache without a second request.
Types ¶
type Release ¶
type Release struct {
Version string // e.g. "0.2.0" (the tag without its prefix)
Tag string // e.g. "v0.2.0"
AssetURL string // GitHub API asset URL (octet-stream download) for this platform
}
Release is the latest release plus the asset for the running platform.
func Cached ¶
func Cached() *Release
Cached returns the latest release from the cached check (no network), or nil when there is none. Its AssetURL is empty: it can be reported, not applied.
func Check ¶
Check returns the latest release: the cached one while it is fresh, else a live lookup, which it caches. For a long-running process (serve), which can afford the request off its hot path; a short command uses Cached and Refresh.