selfupdate

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package selfupdate replaces the running binary with a newer release.

Fetch the release asset for this GOOS/GOARCH, verify its SHA-256 against the checksums the release ships, and rename it over the current executable. Nothing is executed before it is verified, and a failed verification leaves the running binary untouched.

The dashboard notices the replacement on its own: internal/selfreload watches the executable and restarts into whatever is there now, so an update applied from another terminal takes effect without anyone quitting.

Index

Constants

View Source
const DefaultRepo = "maci0/toktop"

DefaultRepo is the GitHub repository releases are fetched from.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, rel *Release) (string, error)

Apply downloads, verifies, and installs the release over the running executable. It returns the path that was replaced.

The new binary is written next to the current one (same filesystem, so the rename is atomic) and only renamed after its checksum matches. A failed verification leaves the running binary untouched.

func AssetName

func AssetName(version string) string

AssetName is the binary this platform needs from a release. It must match what the Makefile's dist target produces, or self-update finds nothing.

func ChecksumFor

func ChecksumFor(listing, name string) (string, bool)

ChecksumFor finds one file's expected hash in a `sha256sum` style listing ("<hex> <name>", with an optional binary-mode asterisk).

func ChecksumListing

func ChecksumListing(archive []byte) (string, error)

ChecksumListing pulls checksums.txt out of the tar.gz the release ships it in. The archive holds exactly that one file, so anything else in it is a reason to stop rather than to keep looking.

Types

type Release

type Release struct {
	TagName string `json:"tag_name"`
	HTMLURL string `json:"html_url"`
	Assets  []struct {
		Name string `json:"name"`
		URL  string `json:"browser_download_url"`
		Size int64  `json:"size"`
	} `json:"assets"`
}

Release is the subset of a GitHub release that matters here.

func Check

func Check(ctx context.Context, repo string) (*Release, error)

Check queries the latest release. It is never called on the startup path: a version check must not stand between the user and the first review.

func (*Release) NewerThan

func (r *Release) NewerThan(current string) bool

NewerThan reports whether the release is a different version from current. Comparison is deliberately exact rather than semver-aware: releases are the source of truth, and a "downgrade" published on purpose should be applied.

func (*Release) Version

func (r *Release) Version() string

Version is the release version without a leading "v".

Jump to

Keyboard shortcuts

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