Help us shape the future of Go! Take the 2026 Go Developer Survey

update

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package update checks whether a newer jamformer release is available and works out how to tell the user to upgrade.

Three things keep this from getting in the way. The check runs in the background from a short-lived goroutine, so a slow or unreachable network never delays a run; its result is cached on disk so a request goes out at most once a day; and the advice it prints names the upgrade command for the way this binary was actually installed, because "a new version is available" with no next step is a notification, not help.

Index

Constants

View Source
const (

	// ReleasesPage is where a user without a package manager goes.
	ReleasesPage = "https://github.com/" + repo + "/releases/latest"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InstallMethod

type InstallMethod int

InstallMethod is how this binary got onto the machine, which decides the upgrade instruction.

const (
	// InstallUnknown covers anything not positively identified. The releases
	// page is always correct advice, so this is a safe default rather than a
	// failure.
	InstallUnknown InstallMethod = iota
	// InstallHomebrew is a binary under a Homebrew prefix or Cellar.
	InstallHomebrew
	// InstallGoInstall is a binary in GOBIN / GOPATH/bin.
	InstallGoInstall
	// InstallSource is a binary sitting in a source checkout.
	InstallSource
	// InstallPackage is a system path a macOS .pkg or a manual copy installs
	// to.
	InstallPackage
)

func DetectInstallMethod

func DetectInstallMethod() InstallMethod

DetectInstallMethod works out how this binary was installed, from where it sits on disk. Every branch is a guess about a filesystem layout, so the unknown case has to stay useful: it points at the releases page, which is right however the binary arrived.

func (InstallMethod) String

func (m InstallMethod) String() string

String names the method, for -version output and tests.

type Result

type Result struct {
	// Available is true only when a strictly newer release was found.
	Available bool
	// Current and Latest are the two versions compared, without a leading "v".
	Current string
	Latest  string
	// URL is the release's page.
	URL string
	// Method is how this binary appears to have been installed.
	Method InstallMethod
}

Result carries the outcome of a check.

func Check

func Check(ctx context.Context, current string) (Result, error)

Check looks for a newer release than current. It returns an error only for the caller's information: every caller treats a failed check as "no notice" rather than a problem, because an update check is not part of the job the user asked for.

The check is skipped, with no error, when the current version is not a release version (a `go build` from source reports "dev", and there is nothing meaningful to compare), or when JAMFORMER_SKIP_UPDATE_CHECK is set.

func (Result) Notice

func (r Result) Notice() string

Notice renders the one-line advisory, or "" when there is nothing to say.

func (Result) UpgradeHint

func (r Result) UpgradeHint() string

UpgradeHint returns the command or action to upgrade, phrased for the detected install method.

Jump to

Keyboard shortcuts

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