update

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, r *Release, progress io.Writer) error

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

func Notice(r *Release) string

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.

func Refresh

func Refresh(ctx context.Context) error

Refresh runs a live check and updates the cache. Called from the detached background refresh (see cmd/anfra), never in a command's hot path.

func Stale

func Stale() bool

Stale reports whether the cached check is missing or older than the TTL.

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

func Check(ctx context.Context) (*Release, error)

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.

func Latest

func Latest(ctx context.Context) (*Release, error)

Latest fetches the newest release and resolves the asset for this platform.

func (*Release) IsNewer

func (r *Release) IsNewer() bool

IsNewer reports whether the latest version is newer than the running one, so worth announcing and installing. Never for a build from source: it was built on purpose, and a release would replace it with something else.

Jump to

Keyboard shortcuts

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