update

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package update provides self-update detection and installation method logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentBinaryPath

func CurrentBinaryPath() (string, error)

CurrentBinaryPath returns the absolute path to the running executable, resolving any symlinks.

func FetchLatest

func FetchLatest(apiURL string) (string, error)

FetchLatest is an exported wrapper around fetchLatestVersion. If apiURL is empty it uses the default GitHub releases URL.

func IsNewer

func IsNewer(current, latest string) bool

IsNewer reports whether latest is a higher semver than current. Returns false when either value is not valid semver (e.g. "dev").

func SelfUpdate

func SelfUpdate(binaryPath, newVersion, baseURL string) error

SelfUpdate downloads the release archive for newVersion, verifies its checksum, extracts the binary, and atomically replaces binaryPath.

baseURL is a template with {tag} and {name} placeholders. Pass an empty string to use the default GitHub releases URL.

Types

type Cache

type Cache struct {
	LatestVersion   string    `json:"latest_version"`
	CheckedAt       time.Time `json:"checked_at"`
	NotifiedAt      time.Time `json:"notified_at,omitempty"`
	NotifiedVersion string    `json:"notified_version,omitempty"`
}

Cache holds the persisted update-check state between CLI runs.

type CheckResult

type CheckResult struct {
	// ShouldNotify is true when the user should be told about a new version.
	ShouldNotify bool
	// LatestVersion is the newest version available (set when ShouldNotify is true).
	LatestVersion string
	// RefreshDone is closed when the background cache refresh completes.
	// Nil if no refresh was needed. Callers can select on this to wait.
	RefreshDone <-chan struct{}
}

CheckResult holds the outcome of CheckForUpdate.

func CheckForUpdate

func CheckForUpdate(currentVersion, configDir, apiURL string) CheckResult

CheckForUpdate implements the cache-then-notify pattern:

  1. Read cache synchronously (fast path).
  2. If cache is stale, spawn a background goroutine to refresh it for the NEXT run.
  3. Compare cached latest vs currentVersion.
  4. Apply notification-suppression rules.
  5. If notifying, update the cache and return CheckResult with ShouldNotify=true.

If the cache is stale, RefreshDone will be a non-nil channel that closes when the background refresh completes. Callers can optionally wait on it to ensure the cache is populated before the process exits.

type InstallMethod

type InstallMethod int

InstallMethod describes how the binary was installed.

const (
	// DirectDownload means the binary was downloaded directly (e.g. from GitHub Releases).
	DirectDownload InstallMethod = iota
	// Homebrew means the binary was installed via Homebrew.
	Homebrew
	// GoInstall means the binary was installed via go install.
	GoInstall
)

func DetectInstallMethod

func DetectInstallMethod(binaryPath string) InstallMethod

DetectInstallMethod returns the InstallMethod for the given binary path. Use filepath.ToSlash for cross-platform path comparison.

func (InstallMethod) String

func (m InstallMethod) String() string

String returns the human-readable name of the install method.

Jump to

Keyboard shortcuts

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