Documentation
¶
Overview ¶
Package update implements VORTEX's self-update machinery: querying the GitHub releases API, downloading and verifying release archives, and atomically hot-swapping the running binary. It is split from the CLI command so the logic is testable without a terminal and reusable by future agents (e.g. the DevOps self-healing agents in M14). Stdlib only — no external HTTP client.
Index ¶
- Variables
- func AssetName(goos, goarch string) string
- func AtomicReplace(newBin, targetPath string) error
- func Download(ctx context.Context, url, dest, expectedSHA256 string, progress func(n int64)) error
- func Extract(archive, destDir, filename string) (string, error)
- func FetchChecksums(ctx context.Context, release *Release) (map[string]string, error)
- func ParseChecksums(s string) map[string]string
- func Rollback(targetPath string) error
- func SetUserAgent(ua string)
- type Asset
- type Release
Constants ¶
This section is empty.
Variables ¶
var ErrNoReleases = errors.New("no releases published yet")
ErrNoReleases is returned by FetchLatestRelease when the repository has no published releases yet (the GitHub API answers 404). It is informational rather than a failure — callers should treat it as "nothing to update to".
Functions ¶
func AtomicReplace ¶
AtomicReplace replaces the binary at targetPath with newBin: the existing target is moved to targetPath+".bak", then newBin is copied into place with 0755 permissions. On any failure it restores the .bak. The caller is responsible for removing the .bak after verifying the new binary.
func Download ¶
Download streams url to the file at dest, verifying its SHA-256 against expectedSHA256 (hex). progress, if non-nil, is called with the cumulative byte count roughly every 1MB. On a checksum mismatch or a cancelled context, the partial dest file is removed and an error is returned.
func Extract ¶
Extract pulls the single entry named filename out of a .tar.gz or .zip archive into destDir, returning the path to the extracted file. The archive format is detected from the archive's extension. Entries whose path escapes destDir (zip-slip: containing ".." or absolute paths) are rejected.
func FetchChecksums ¶
FetchChecksums downloads and parses the release's checksums.txt, returning a map of filename → SHA-256 hex.
func ParseChecksums ¶
ParseChecksums turns "<hex> <filename>" lines into a filename→hash map.
func Rollback ¶
Rollback restores targetPath+".bak" back to targetPath. It is idempotent: if no .bak exists it returns nil.
func SetUserAgent ¶
func SetUserAgent(ua string)
SetUserAgent sets the User-Agent string sent to GitHub (e.g. the build version). Safe to call once at startup.
Types ¶
type Asset ¶
Asset is a single downloadable file attached to a release.
func AssetForPlatform ¶
AssetForPlatform returns the release archive Asset for the given platform. The naming follows GoReleaser's config: vortex_<goos>_<goarch>.tar.gz for linux/darwin and .zip for windows.
func CurrentPlatformAsset ¶
CurrentPlatformAsset is a convenience wrapper for the running platform.