Documentation
¶
Overview ¶
Package update implements a self-updater that fetches the latest release from GitHub and swaps the running binary in place. It uses only the standard library: the GitHub REST API for release discovery and an atomic rename-based swap that also works on Windows, where a running executable cannot be overwritten but can be renamed aside.
Private repositories are supported via a GitHub token, discovered from GH_TOKEN / GITHUB_TOKEN or, failing that, the `gh` CLI (`gh auth token`).
Index ¶
- Constants
- func Apply(ctx context.Context, asset *Asset, token, exePath string) error
- func AssetName() string
- func CompareVersions(a, b string) int
- func DownloadAsset(ctx context.Context, asset *Asset, token, destPath string) error
- func Run(ctx context.Context, repo, currentVersion string, checkOnly bool, ...) error
- type Asset
- type Release
Constants ¶
const DefaultRepo = "joshkerr/goplexcli"
DefaultRepo is the GitHub "owner/name" the updater pulls releases from.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply downloads asset and replaces the executable at exePath with it. The swap renames the running binary to "<exe>.old" before moving the new binary into place, which is the only approach that works while the binary is executing on Windows. On success it best-effort removes the ".old" file.
The download uses the API asset endpoint with Accept: application/octet-stream so it works for private repos when token is set; GitHub redirects to a signed URL and Go drops the Authorization header on the cross-host redirect.
func AssetName ¶
func AssetName() string
AssetName returns the release asset name expected for the current platform, matching the names produced by `make build-all` (e.g. "goplexcli-darwin-arm64", "goplexcli-windows-amd64.exe").
func CompareVersions ¶
CompareVersions compares two dotted version strings, ignoring a leading "v". It returns -1 if a < b, 0 if equal, and 1 if a > b. Non-numeric components compare as 0, so unparseable versions degrade to "equal" rather than erroring.
func DownloadAsset ¶ added in v0.3.15
DownloadAsset downloads asset to destPath, authenticating with token when set (required for private repos). It uses the API asset endpoint with Accept: application/octet-stream so GitHub redirects to a signed URL. The caller controls timeouts via ctx (pass a generous deadline — GUI bundles are larger than the CLI binary). It verifies the byte count against asset.Size when known. Used by the GUI self-updater, which downloads a zip bundle rather than swapping a bare binary.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
URL string `json:"url"`
BrowserDownloadURL string `json:"browser_download_url"`
Size int64 `json:"size"`
}
Asset is a single downloadable file attached to a release. URL is the API asset endpoint (used for authenticated downloads on private repos); BrowserDownloadURL is the public direct link.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
HTMLURL string `json:"html_url"`
Assets []Asset `json:"assets"`
}
Release is the subset of a GitHub release we care about.
func LatestRelease ¶
LatestRelease fetches the most recent published release for repo ("owner/name"). If token is non-empty it is sent as a bearer credential, which is required for private repositories.
func ResolveLatest ¶ added in v0.3.15
ResolveLatest fetches the latest release for repo, trying each GitHub token candidate in turn (env vars, the gh CLI, then unauthenticated) until one succeeds. It returns the release and the token that worked (empty when the unauthenticated attempt succeeded), so the caller can reuse that same token to download the release's assets. This tolerates a stale env token by falling back to the gh CLI and finally to a public request.