update

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package update finds out whether a newer Chapar release is out, and downloads, verifies and installs it where the platform allows.

Index

Constants

View Source
const LatestURL = "https://api.github.com/repos/chapar-rest/chapar/releases/latest"

LatestURL is the GitHub API endpoint for the newest published release. Drafts and prereleases never show up there.

View Source
const SigSuffix = ".sig"

SigSuffix is appended to an asset's name to get its signature asset.

Variables

View Source
var ErrUnsupported = errors.New("this copy of Chapar can't update itself")

ErrUnsupported means this copy of Chapar cannot update itself; the user downloads the new version instead.

Functions

func AssetName

func AssetName(version, goos, goarch string) (string, bool)

AssetName is the release file for the app on goos/goarch, following the artifact pattern in yoga.toml.

func BrewUpgrade

func BrewUpgrade(context.Context, io.Writer) error

func Cleanup

func Cleanup()

func Install

func Install(context.Context, string) error

func InstalledVersion

func InstalledVersion() string

InstalledVersion is only known for macOS app bundles.

func IsRelease

func IsRelease(v string) bool

IsRelease reports whether v is a release version like "v1.2.3".

func Newer

func Newer(current, latest string) bool

Newer reports whether latest is a later version than current. A current version that is not a release (a dev build) is never behind.

func ParsePrivateKey

func ParsePrivateKey(s string) (ed25519.PrivateKey, error)

ParsePrivateKey decodes a base64 ed25519 seed.

func ParsePublicKey

func ParsePublicKey(s string) (ed25519.PublicKey, error)

ParsePublicKey decodes a base64 ed25519 public key.

func Restart

func Restart() error

func Sign

func Sign(key ed25519.PrivateKey, name, sha256Hex string) string

Sign returns the base64 signature file contents for an asset.

Types

type Asset

type Asset struct {
	Name string
	URL  string // direct download
	Size int64
	// Digest is GitHub's "sha256:<hex>" for the file, empty on old releases.
	Digest string
}

Asset is one file attached to a release.

type Client

type Client struct {
	HTTP      *http.Client
	LatestURL string
	UserAgent string
}

Client fetches release info and assets. The zero value uses LatestURL and an HTTP client that honors the proxy environment variables.

func (Client) Download

func (c Client) Download(ctx context.Context, r Release, name string, progress Progress) (string, error)

Download fetches the named asset of r into a temp file and checks it against its signature, and GitHub's digest when there is one. The caller removes the returned file.

func (Client) Latest

func (c Client) Latest(ctx context.Context) (Release, error)

Latest returns the newest published release.

type Method

type Method int

Method is how this copy of Chapar gets a new version.

const (
	// Manual: the user downloads and installs the new version.
	Manual Method = iota
	// InApp: Install replaces this copy in place.
	InApp
	// Homebrew: the app came from the Homebrew cask, which BrewUpgrade runs.
	Homebrew
)

func Detect

func Detect() Method

Detect: Linux installs put the binary under /usr/local/bin with sudo, so the app can't replace itself; the user downloads the new version.

type Progress

type Progress func(done, total int64)

Progress reports bytes downloaded so far out of total (0 when unknown).

type Release

type Release struct {
	Version string // tag, e.g. "v0.12.0"
	URL     string // release page, where the notes are
	Notes   string // markdown body
	Assets  []Asset
}

Release is a published Chapar release.

func (Release) Asset

func (r Release) Asset(name string) (Asset, bool)

Asset returns the release asset with the given name.

Jump to

Keyboard shortcuts

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