updatecheck

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package updatecheck implements an opt-in, fail-silent "newer release available" check for the refresh CLI.

It queries the GitHub Releases API for the latest tag, compares it against the running version with a small semver comparison, and (when the local build is behind) returns a one-line upgrade hint. Results are throttled via a small JSON cache under the user config dir so the network is hit at most once per day; every failure path is silent so the check never disrupts the CLI.

Index

Constants

View Source
const DefaultBaseURL = "https://api.github.com/repos/dantech2000/refresh/releases/latest"

DefaultBaseURL is the GitHub Releases "latest" endpoint for this project.

Variables

This section is empty.

Functions

func UpgradeHint

func UpgradeHint(current, latest string) string

UpgradeHint returns a one-line "newer version available" message when latest is strictly newer than current, or "" otherwise (including when either is "dev"/unparseable). current/latest may be with or without a leading "v".

Types

type Checker

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

Checker performs throttled, fail-silent update checks. The zero value is not usable; construct it with New.

func New

func New(opts ...Option) *Checker

New builds a Checker with production defaults, applying any options.

func (*Checker) LatestTag

func (c *Checker) LatestTag(ctx context.Context) (string, error)

LatestTag returns the most recent release tag, using the cached value when it is fresher than checkInterval and otherwise fetching once and updating the cache. It is fail-silent: any network/parse/cache error yields ("", nil-ish) without surfacing the error to the caller's hot path.

type Option

type Option func(*Checker)

Option customizes a Checker. Tests inject a base URL, HTTP client, cache path, and clock so no real network or real home dir is touched.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the releases endpoint.

func WithCachePath

func WithCachePath(p string) Option

WithCachePath overrides the cache file path.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient overrides the HTTP client.

func WithNow

func WithNow(now func() time.Time) Option

WithNow overrides the clock.

Jump to

Keyboard shortcuts

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