Documentation
¶
Overview ¶
Package upgradecheck handles passive "new version available" notices emitted after unrelated commands succeed. Results are cached to disk with a 24-hour TTL so normal use never makes more than one GitHub API call per day per user.
Index ¶
Constants ¶
const DefaultTTL = 24 * time.Hour
DefaultTTL is how long a cache file is considered fresh.
Variables ¶
This section is empty.
Functions ¶
func CachePath ¶
CachePath returns the path to the cache file, creating the containing directory if needed. Follows XDG on Linux/macOS and %LOCALAPPDATA% on Windows.
func Disabled ¶
Disabled reports whether passive upgrade checks are suppressed in the current environment. The answer combines: explicit opt-out flag, TRUESTAMP_NO_UPGRADE_CHECK env var, CI detection, non-TTY stderr, and a "dev" current version.
The cmd layer is responsible for reading the --no-upgrade-check flag and passing it in via flagDisabled.
func MaybeNotify ¶
MaybeNotify writes a single-line "new version available" notice to w if an upgrade is available. No-op when Disabled() returns true.
The flow:
- If cache is fresh (<24h), use the cached result, no network.
- Otherwise, spawn a goroutine with a 2-second deadline to refresh the cache. Wait up to 500ms for it to complete; if it doesn't, we skip emitting a notice this invocation. The cache write is still committed when the goroutine finishes, so the next run picks it up.
All errors are swallowed, upgrade checks must never interfere with the primary command's output.
func WriteCache ¶
WriteCache atomically overwrites the cache file. Errors are returned to the caller but are typically non-fatal (the notification path ignores them).
Types ¶
type Cache ¶
type Cache struct {
LastChecked time.Time `json:"last_checked"`
LatestVersion string `json:"latest_version"`
CheckedFromVersion string `json:"checked_from_version"`
}
Cache holds the most recent upgrade check result. Time is always stored in UTC.