Documentation
¶
Overview ¶
Package selfupdate replaces the running gotools binary with the newest release for this operating system and architecture.
A Source says where releases come from and fetches them: the latest tag, the checksum manifest and the binary. An Updater installs one: it downloads the binary, checks its SHA-256 against the release's checksums, proves the candidate runs, and swaps it in with the old binary kept as ".old" until the new one has run from its final location. Nothing is replaced unless the checksum matched and the candidate ran.
The checksum is an integrity check against the release, not proof of authorship; installing with `go install` is the stronger path.
Index ¶
- Constants
- func RunVersion(ctx context.Context, bin string) error
- type Doer
- type Relation
- type Source
- func (s Source) Asset() string
- func (s Source) AssetURL(tag, asset string) string
- func (s Source) Checksum(ctx context.Context, tag, asset string) (string, error)
- func (s Source) Download(ctx context.Context, tag, asset string, w io.Writer) (string, error)
- func (s Source) Latest(ctx context.Context) (string, error)
- type Updater
Constants ¶
const ( Repo = "piusalfred/gotools" Name = "gotools" )
Repo is the GitHub repository releases are published to, and Name the program's name, which prefixes every release asset.
const Checksums = "checksums-sha256.txt"
Checksums is the release asset that lists the SHA-256 of every binary.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Relation ¶
type Relation int
Relation is how the running version compares to the latest release.
type Source ¶
type Source struct {
APIURL string // JSON of the latest release
DownloadBase string // <base>/<tag>/<asset>
Client Doer
GOOS, GOARCH string
UserAgent string
}
Source says where releases come from. Tests point it at a server.
func GitHub ¶
GitHub is the Source of the project's releases for this platform. version names the running program in the User-Agent.
type Updater ¶
type Updater struct {
Source Source
// Check proves that the binary at the path runs. RunVersion when nil.
Check func(ctx context.Context, bin string) error
// Out narrates the update; Err reports a rollback.
Out, Err io.Writer
}
Updater installs a release.
func (*Updater) Install ¶
Install downloads tag's binary for the platform, verifies it and swaps it in for target.
The candidate is written next to the target, so the final rename never crosses a filesystem, and a directory that cannot be written to ends the update before anything is downloaded. It must match the release's checksum and pass Check before it replaces anything; after the swap it must pass Check again from its final path, or the old binary is put back.