selfupdate

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package selfupdate replaces the running executable with a newer stable GitHub release. It needs nothing beyond the standard library.

A release is a tag vX.Y.Z whose assets are <Name>-<os>-<arch> for each platform and checksums.txt in sha256sum format. The new binary must print its bare X.Y.Z for --version, which is checked before anything is replaced.

Index

Constants

This section is empty.

Variables

View Source
var ErrCurrent = errors.New("selfupdate: already the latest version")

ErrCurrent reports that this build already is the latest release.

Functions

func Version

func Version() string

Version returns this build's version: the bare X.Y.Z of the git tag it was built at, or "dev" for any other build. Go stamps the tag into binaries built from a clean checkout, so no build flags are needed.

Types

type Release

type Release struct {
	Version string // bare X.Y.Z
	Newer   bool   // than Version(); a dev build treats every release as newer
	// contains filtered or unexported fields
}

Release is a stable release of the repository.

type Updater

type Updater struct {
	Repository string // owner/name
	Name       string // asset prefix: releases contain <Name>-<os>-<arch>
	Token      string
	Client     *http.Client
}

Updater names the GitHub repository that publishes this program's releases. Token is optional for public repositories and is sent only to the GitHub API, never to the host that serves downloads. Client is optional.

func (Updater) Check

func (updater Updater) Check(ctx context.Context) (Release, error)

Check returns the latest stable release. It touches nothing on disk.

func (Updater) Update

func (updater Updater) Update(ctx context.Context, executable string) (string, error)

Update installs the latest stable release over executable, which is normally the result of os.Executable. Symlinks are resolved, the download is verified against checksums.txt, the new file must print the release version for --version, and the replacement is one atomic rename. Any failure leaves the current executable untouched. It returns the installed version, or ErrCurrent.

Jump to

Keyboard shortcuts

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