update

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package update tells the user when a newer pano release exists. It is notify-only by design (ADR 0010): at most once a day it asks GitHub's public releases endpoint for the latest tag, compares it with the running version and hands back a one-line hint — it never downloads or installs anything, so Homebrew (or go install) stays the only thing that changes the binary.

The check is skipped for development builds, in CI, without a terminal, with --json, when PANO_NO_UPDATE_CHECK or DO_NOT_TRACK is set, when [updates] check = false in config.toml, or when the binary was built with Default set to "off". The request bypasses every proxy (including pano itself) and carries nothing but pano's version in its User-Agent.

Index

Constants

View Source
const EnvDisable = "PANO_NO_UPDATE_CHECK"

EnvDisable turns the check off for one user or one shell.

View Source
const EnvDoNotTrack = "DO_NOT_TRACK"

EnvDoNotTrack is the cross-tool opt-out (https://donottrack.sh). An update check is not telemetry, but a user who set it does not want tools calling home on their own, so pano honours it.

View Source
const Interval = 24 * time.Hour

Interval is how long a check result is trusted before asking again.

View Source
const Repo = "OrRon/pano"

Repo is the GitHub repository whose releases are checked.

Variables

View Source
var Default = "on"

Default is the build-time switch. Packagers who must not ship a version check (Debian, Fedora, …) compile it out with

-ldflags '-X github.com/orron/pano/internal/update.Default=off'

instead of patching the source.

Functions

func Disabled

func Disabled(current string, getenv func(string) string, paths config.Paths) string

Disabled returns why an automatic check must not run, or "" when it may. It looks at the build, the environment and the config file — everything but the terminal and the command, which the caller knows better.

func Hint

func Hint(exe string, getenv func(string) string) string

Hint returns the upgrade command for the way exe was installed: a Homebrew Caskroom/Cellar path → brew, a Go bin dir → go install, anything else → the release page.

func IsDev

func IsDev(v string) bool

IsDev reports whether v is a local or untagged build: "dev", "(devel)", anything git-describe produced past a tag ("v0.3.0-4-gabc1234", "…-dirty").

func Newer

func Newer(a, b string) bool

Newer reports whether semantic version a is newer than b. Tags may carry a leading "v"; a pre-release ("-beta.1") sorts before its release; anything unparsable is never newer.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker runs Check in the background so a command's own work is never delayed by the network.

func Start

func Start(ctx context.Context, o Options) *Checker

Start begins a check; the result is read with Result or Wait.

func (*Checker) Result

func (c *Checker) Result() *Info

Result returns the outcome if the check has finished, else nil. Safe on a nil Checker.

func (*Checker) Wait

func (c *Checker) Wait(d time.Duration) *Info

Wait blocks up to d for the check to finish and returns Result. Safe on a nil Checker.

type Info

type Info struct {
	// Current is the running version, Latest the newest release tag with the
	// leading "v" removed. Available is true when Latest is newer.
	Current   string `json:"current"`
	Latest    string `json:"latest"`
	Available bool   `json:"update_available"`
	// URL is the release page; Hint the upgrade command that matches how
	// this binary was installed (brew, go install, or the release page).
	URL  string `json:"url"`
	Hint string `json:"hint"`
}

Info is the result of a check.

func Check

func Check(ctx context.Context, o Options) (*Info, error)

Check asks for the latest release, honouring the cache, and reports whether it is newer than o.Current. A network failure is an error the caller should swallow: it must never turn into output on a working command.

type Options

type Options struct {
	Current   string       // running version (cli.Version())
	StatePath string       // cache file; "" disables caching
	Force     bool         // ignore a fresh cache entry
	Exe       string       // executable path for Hint; default os.Executable()
	HTTP      *http.Client // default: direct (no proxy), 3 s timeout
	Getenv    func(string) string
	Now       func() time.Time
	Endpoint  string        // default https://api.github.com/repos/<Repo>/releases/latest
	Interval  time.Duration // default Interval
}

Options configure a check. Zero values are filled from the environment.

Jump to

Keyboard shortcuts

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