update

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package update implements the self-update flow: discover the newest GitHub release, compare it to the running version, and swap the executable for the freshly downloaded (checksum-verified) release binary. Checks are throttled through a small cache file so startup never spams the network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetName

func AssetName(version string) string

AssetName is the release archive for this OS/arch, e.g. sleeperagent_0.5.0_darwin_arm64.tar.gz (zip on Windows).

func CleanupOld

func CleanupOld()

CleanupOld removes the "<exe>.old" left behind by a Windows self-update. Best-effort: it fails silently while an old instance still runs.

func Newer

func Newer(current, latest string) bool

Newer reports whether latest is strictly newer than current. Unparseable versions (e.g. a "dev" source build) are never considered outdated.

func Parseable

func Parseable(v string) bool

Parseable reports whether v looks like a release version ("0.5.0", "v0.5.0"). Source builds report "dev" (or a pseudo-version) and can't be meaningfully compared to releases.

func RecordCheck

func RecordCheck(latest string)

RecordCheck persists the result (or attempt) of an update check so the next startup within maxAge skips the network entirely.

func ShouldCheck

func ShouldCheck(maxAge time.Duration) bool

ShouldCheck reports whether the last check is older than maxAge. A missing or unreadable cache means "check now".

Types

type Client

type Client struct {
	BaseURL string
	HTTP    *http.Client
}

Client talks to the release host. BaseURL is normally https://github.com; SLEEPERAGENT_UPDATE_BASE_URL overrides it (tests, mirrors).

func New

func New() *Client

New returns a Client with sane timeouts.

func (*Client) Apply

func (c *Client) Apply(ctx context.Context, version string) error

Apply downloads the given release, verifies it against checksums.txt, and replaces the running executable. The running process keeps executing the old code; the new version takes effect on the next start.

func (*Client) ApplyTo

func (c *Client) ApplyTo(ctx context.Context, version, target string) error

ApplyTo is Apply targeting an explicit path (separated out for tests).

func (*Client) LatestVersion

func (c *Client) LatestVersion(ctx context.Context) (string, error)

LatestVersion returns the newest release tag (e.g. "v0.5.0"). It reads the redirect target of /releases/latest, which needs no API token and is not rate-limited like the REST API.

Jump to

Keyboard shortcuts

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