Help us shape the future of Go! Take the 2026 Go Developer Survey

update

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package update keeps shed current. It checks GitHub for new releases, downloads them and verifies their signed checksums, and swaps the shed binary on disk. Restarting into the new binary is up to the caller.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupported means this build cannot update itself.
	ErrUnsupported = errors.New("update: this build cannot update itself")
	// ErrNoUpdate means there is no newer release to download.
	ErrNoUpdate = errors.New("update: no newer release")
	// ErrBusy means a check, download, or install is already in progress.
	ErrBusy = errors.New("update: an update operation is in progress")
	// ErrNotStaged means no release has been downloaded to install.
	ErrNotStaged = errors.New("update: no update has been downloaded")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Repo is the GitHub repository releases are published to, "owner/name".
	Repo string
	// Version is the running version, a semver tag such as "v1.2.3".
	// Anything else is a development build, which cannot update itself.
	Version string
	// PublicKey is the minisign public key that signs checksums.txt.
	PublicKey string
	// Binary is the path of the shed binary that Install replaces.
	Binary string
	// Dir holds downloaded releases until they are installed.
	Dir      string
	Settings Settings
	// HTTPClient makes the GitHub requests. Nil means a client with a
	// 10-minute timeout.
	HTTPClient *http.Client
	// APIURL is the GitHub API base URL. Empty means api.github.com.
	APIURL string
	// Interval is the time between background checks. Zero means 6 hours.
	Interval time.Duration
	Log      *slog.Logger
}

Config configures an Updater.

type Release

type Release struct {
	// Version is the release tag, such as "v1.2.3".
	Version     string
	URL         string
	Notes       string
	PublishedAt time.Time
	// contains filtered or unexported fields
}

Release is a published shed release.

type Settings

type Settings interface {
	// Setting returns the value of key, and false if it is not set.
	Setting(ctx context.Context, key string) (string, bool, error)
	SetSetting(ctx context.Context, key, value string) error
}

Settings stores the update preferences.

type State

type State string

State is what the Updater is doing.

const (
	Idle        State = "idle"
	Checking    State = "checking"
	Downloading State = "downloading"
	Restarting  State = "restarting"
)

States of an Updater.

type Status

type Status struct {
	Current string
	// Latest is the latest release, or nil until a check finds one.
	Latest *Release
	// Available reports whether Latest is newer than Current.
	Available bool
	// CheckedAt is the time of the last successful check.
	CheckedAt time.Time
	State     State
	// Staged is the version downloaded, verified, and ready to install.
	Staged string
	// Err is the last check or download failure.
	Err          string
	AutoDownload bool
	// Unsupported says why this build cannot update itself, or is empty.
	Unsupported string
}

Status reports the running version, the latest release, and the progress of updating to it.

type Updater

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

Updater checks for, downloads, and installs shed releases.

func New

func New(cfg Config) (*Updater, error)

New returns an Updater. It fails if the public key is invalid.

func (*Updater) Check

func (u *Updater) Check(ctx context.Context) (Status, error)

Check asks GitHub for the latest release and, with automatic downloads on, starts downloading it if it is newer. A failed check is returned and also reported in the status.

func (*Updater) Download

func (u *Updater) Download(ctx context.Context) (Status, error)

Download starts downloading the latest release in the background, unless it is already downloaded. Run performs the download.

func (*Updater) Install

func (u *Updater) Install(ctx context.Context) (Status, error)

Install replaces the shed binary with the downloaded release, keeping the replaced one next to it with a .prev suffix. On success the Updater stays in the Restarting state: the caller is expected to restart shed.

func (*Updater) Run

func (u *Updater) Run(ctx context.Context)

Run checks for a new release a minute after it starts and then periodically, and performs downloads, until ctx is done. It does nothing for builds that cannot update themselves.

func (*Updater) SetAutoDownload

func (u *Updater) SetAutoDownload(ctx context.Context, on bool) (Status, error)

SetAutoDownload turns automatic downloads on or off. Turning them on starts downloading a newer release that is already known.

func (*Updater) Status

func (u *Updater) Status(ctx context.Context) (Status, error)

Status returns the current status.

Jump to

Keyboard shortcuts

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