release

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package release checks for a newer published release and replaces the running binary with it.

It fails closed on verification. install.sh warns and continues when checksums.txt is missing, because a first install with no binary at all is worse than an unverified one. An update is the opposite case: there is already a working binary on disk, so an unverifiable download has nothing to offer and is refused.

Stdlib only, like the rest of the project. Nothing here needs a dependency.

Index

Constants

View Source
const Repo = "AlleyBo55/KiroBuff"

Repo is the upstream project. Kept as a constant rather than a flag: pointing a self-updater at an arbitrary repository is a way to install someone else's binary under this one's name.

Variables

View Source
var ErrDevBuild = errors.New("this is a development build, not a released version")

ErrDevBuild means the running binary has no release version to compare against, so "newer" is not a question that can be answered.

View Source
var ErrNoAsset = errors.New("no release asset for this platform")

ErrNoAsset means the release exists but carries nothing for this platform.

Functions

func AssetName

func AssetName(tag, goos, goarch string) string

AssetName returns the archive filename GoReleaser produces for a platform. It must stay in step with the name_template in .goreleaser.yaml.

func Newer

func Newer(current, latest string) (bool, error)

Newer reports whether latest is a higher version than current.

An unparseable current version returns ErrDevBuild: a locally built binary reports "dev", and treating that as older than everything would let a stray `kirobuff update` overwrite a build someone is actively debugging.

func Platform

func Platform() (string, string)

Platform returns the GOOS and GOARCH the running binary was built for.

func Replace

func Replace(dest string, payload []byte) error

Replace overwrites dest with payload.

The new file is written beside the target so the final step is a rename on the same filesystem, which is atomic: an interrupted update leaves either the old binary or the new one, never a half-written file. The old binary is moved aside first because Windows refuses to rename over a running executable.

func Self

func Self() (string, error)

Self returns the path of the running executable, with symlinks resolved.

Resolving matters: a Homebrew or /usr/local/bin symlink points at the real binary, and replacing the link instead of its target would leave the old binary in place and the link no longer shared.

Types

type Release

type Release struct {
	Tag         string
	PublishedAt string
	Notes       string
	URL         string
}

Release is a published release, reduced to what an update needs.

type Source

type Source struct {
	// API is the repository API root, without a trailing slash.
	API string
	// Downloads is the release-asset root, without a trailing slash.
	Downloads string
	// Client performs the requests. nil means a client with a sane timeout.
	Client *http.Client
}

Source is where releases are read from. The zero value is not useful; call Default. The fields exist so tests can point at a local server instead of GitHub.

func Default

func Default() Source

Default returns the upstream source.

func (Source) Fetch

func (s Source) Fetch(tag, goos, goarch string) ([]byte, error)

Fetch downloads the release binary for a platform and returns its bytes.

The archive's checksum is verified against checksums.txt before anything is extracted. A mismatch, a missing checksums.txt, or an absent entry for this archive is an error, not a warning.

func (Source) Latest

func (s Source) Latest() (Release, error)

Latest returns the most recent published release.

The unauthenticated API is rate-limited per IP. A 403 or 429 is reported as such rather than as a generic failure, because the difference decides whether retrying helps.

Jump to

Keyboard shortcuts

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