update

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package update keeps a desktop app up to date from a feed you host: it checks for a newer version, downloads it, verifies it, replaces the app and restarts it.

u := update.New() // feed, key and version from giode.toml, via the giode CLI
rel, err := u.Check(ctx)
if err == nil && rel != nil {
	dl, err := u.Download(ctx, rel, nil)
	if err == nil {
		err = dl.Install() // restarts into the new version
	}
}

The feed is a JSON file listing the latest version and a download per platform, signed with an Ed25519 key: `giode update-key` makes the key pair (the public half goes into the app), and `giode release` writes the signed feed and the downloads from a build. The app trusts only a feed signed with its key, and only downloads whose SHA-256 the feed lists, so the server needn't be trusted.

Apps installed by a package manager or store - a .deb or .rpm, Flatpak, MSIX, the App Store - are updated by it instead: Check returns ErrManaged for them.

Index

Constants

View Source
const WaitEnv = "GIODE_UPDATE_WAIT_PID"

WaitEnv names the environment variable an updated app is restarted with: the old process's pid, which giode waits for to exit before taking the single-instance lock.

Variables

View Source
var ErrManaged = errors.New("update: the app is installed by a package manager or store, which updates it")

ErrManaged is returned for an app a package manager or store installed and updates.

Functions

func Cleanup

func Cleanup()

Cleanup removes what an earlier update left behind (the replaced program). Call it once at startup.

func Newer

func Newer(a, b string) bool

Newer reports whether version a is newer than b (major.minor.patch, missing parts 0; anything after - or + is ignored).

func Platform

func Platform() string

Platform returns this build's feed key: GOOS-GOARCH, or darwin-universal on macOS.

func Sign

func Sign(privateKey string, data []byte) (string, error)

Sign signs data with a base64 Ed25519 private key, returning the base64 signature the feed's .sig file holds.

func Verify

func Verify(publicKey string, data, sig []byte) error

Verify checks sig, a base64 Ed25519 signature, over data with the base64 public key.

Types

type Asset

type Asset struct {
	// URL is where it is, relative to the feed or absolute.
	URL string `json:"url"`
	// SHA256 is the hex digest of the file; Size its length.
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
	// Kind says how it installs: "exe" (a Windows program replacing
	// the running one), "installer" (a Windows setup program run
	// silently), "app.zip" (a zipped macOS app bundle), "binary" (a
	// Linux program) or "appimage".
	Kind string `json:"kind"`
}

Asset is a download for one platform.

type Download

type Download struct {
	Release *Release
	// Path is the downloaded file.
	Path string
	// contains filtered or unexported fields
}

Download is a downloaded, verified release.

func (*Download) Install

func (d *Download) Install() error

Install replaces the app with the download and restarts it; on success it doesn't return. Close windows and save state first.

type Feed

type Feed struct {
	// Version is the latest version; Notes describe it; Date is when
	// it was released (RFC 3339).
	Version string `json:"version"`
	Notes   string `json:"notes,omitempty"`
	Date    string `json:"date,omitempty"`
	// Assets are the downloads by platform.
	Assets map[string]Asset `json:"assets"`
}

Feed is the update feed.

type Release

type Release struct {
	Version, Notes, Date string
	Asset                Asset
	// contains filtered or unexported fields
}

Release is an available update.

type Updater

type Updater struct {
	// FeedURL is the feed's address; its signature is at FeedURL+".sig".
	FeedURL string
	// PublicKey is the base64 Ed25519 public key the feed is signed
	// with.
	PublicKey string
	// Version is the running version, major.minor.patch.
	Version string
	// Client fetches the feed and downloads; http.DefaultClient when
	// nil.
	Client *http.Client
	// Platform is the feed's key for this build ("windows-amd64",
	// "darwin-universal", "linux-amd64"); detected when empty.
	Platform string
	// Executable is the program (or .app bundle, or AppImage) to
	// replace; detected when empty.
	Executable string
}

Updater checks a feed and installs its releases.

func New

func New() *Updater

New returns an Updater configured by the giode CLI from giode.toml.

func (*Updater) Check

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

Check fetches the feed and returns the release newer than Version for this platform, or nil when the app is up to date.

func (*Updater) Download

func (u *Updater) Download(ctx context.Context, r *Release, progress func(done, total int64)) (*Download, error)

Download fetches the release into a temporary file, checking its SHA-256. progress, when set, is called as bytes arrive.

Jump to

Keyboard shortcuts

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