update

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package update checks whether a newer Caprock release exists and works out the command that would install it.

This is the ONE place in Caprock that talks to the network, and it is off until the user turns it on. Engineering rule 4 ("no outbound calls") is not bent quietly: the check is opt-in, asked for once, visible in the UI with the time of the last check, and revocable. The request carries no body, no identifiers, and no usage data — GitHub learns an IP asked for a release tag, which is what any `brew update` already tells it.

Caprock deliberately does NOT install the update itself. Upgrading means replacing the running binary, so the daemon would be killing the process executing the command — a race whose failure mode is a user left with no working Caprock. Running a package manager on the user's behalf from a web page is also exactly the surface a local tool should not open. Instead we name the exact command for how this copy was installed, and the user runs it.

Index

Constants

View Source
const ReleasesPage = "https://github.com/dspv/caprock/releases/latest"

ReleasesPage is where a user without a package manager goes.

Variables

View Source
var LatestURL = "https://api.github.com/repos/dspv/caprock/releases/latest"

LatestURL is the release endpoint. Overridable in tests.

Functions

func InstallCommand

func InstallCommand() string

InstallCommand returns the upgrade command for how this copy was installed, inferred from the executable's path. When we cannot tell, we say nothing rather than suggest a command that might do the wrong thing — an empty result means the UI offers the release page instead.

func Newer

func Newer(current, latest string) bool

Newer reports whether latest is a strictly newer release than current. A non-release build ("dev", or a `git describe` string with a commit suffix) is never told it is out of date: the person running it built it themselves.

Types

type Checker

type Checker struct {
	// Now is injectable for tests.
	Now func() time.Time
	// HTTPClient is injectable for tests.
	HTTPClient *http.Client
	// MinInterval throttles checks (default 24h). GitHub's tag does not change
	// often enough to justify asking more, and asking more is more exposure.
	MinInterval time.Duration
	// contains filtered or unexported fields
}

Checker holds the cached result. It never checks on its own: the caller decides when, so "opt-in" is enforced at the call site as well as here.

func New

func New() *Checker

New returns a Checker with sane defaults.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, force bool) error

Check asks GitHub for the latest release tag, respecting MinInterval unless forced. A failure is recorded and returned but never escalated: not knowing about an update must not degrade a working dashboard.

func (*Checker) Status

func (c *Checker) Status(enabled bool, current string) Status

Status returns the cached view. It performs no I/O, so the settings endpoint stays instant and a disabled checker can never touch the network.

type Status

type Status struct {
	// Enabled reports whether the user turned checking on.
	Enabled bool `json:"enabled"`
	// Current is the running version.
	Current string `json:"current"`
	// Latest is the newest published version, "" if never checked.
	Latest string `json:"latest,omitempty"`
	// UpdateAvailable is true only when Latest is genuinely newer than Current.
	UpdateAvailable bool `json:"update_available"`
	// Command is how to install it, given how this copy was installed.
	Command string `json:"command,omitempty"`
	// URL is the release page, always safe to offer.
	URL string `json:"url,omitempty"`
	// CheckedAt is the last successful check (unix ms), 0 if never.
	CheckedAt int64 `json:"checked_at,omitempty"`
	// Error is the last failure, if any. A failed check is never fatal.
	Error string `json:"error,omitempty"`
	// Notes is the published release's own description of what changed, as
	// written on GitHub. It arrives in the same response as the tag — asking
	// for the version and then asking again for the notes would be a second
	// request for something we already had.
	Notes string `json:"notes,omitempty"`
	// NotesFor is the version Notes describes. Without it a stale note could
	// be shown beside a different version after a failed check.
	NotesFor string `json:"notes_for,omitempty"`
}

Status is what the UI renders.

Jump to

Keyboard shortcuts

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