Documentation
¶
Overview ¶
Package updater provides binary self-update from GitHub releases.
Uses creativeprojects/go-selfupdate for release detection, checksum verification, archive matching, and atomic binary replacement.
The three-step API (Download, VerifyChecksum, Install) supports the hot-swap upgrade flow (Phase 3) where the binary is downloaded to a temp path, verified, and installed atomically. ApplyUpdate is preserved as a backwards-compatible wrapper for Phase 1.
Index ¶
- Constants
- Variables
- func Install(newBinaryPath string, currentExePath string) error
- func SetTestHooks(check func(ctx context.Context, currentVersion string) (*Release, error), ...)
- func VerifyChecksum(binaryPath string, release *Release) error
- type ApplyError
- type Release
- func ApplyUpdate(ctx context.Context, currentVersion string) (*Release, error)
- func ApplyUpdateAt(ctx context.Context, currentVersion string, currentExePath string) (*Release, error)
- func CheckUpdate(ctx context.Context, currentVersion string) (*Release, error)
- func Download(ctx context.Context, currentVersion string, targetPath string) (*Release, error)
- func ReleaseFromError(err error) (*Release, bool)
Constants ¶
const (
// DefaultSlug is the GitHub repository slug for aimux releases.
DefaultSlug = "thebtf/aimux"
)
Variables ¶
var ( ErrChecksumVerification = errors.New("checksum_verification_failed") ErrDiskFull = errors.New("disk_full") )
Functions ¶
func Install ¶
Install atomically replaces currentExePath with the binary at newBinaryPath.
Uses go-selfupdate/update.Apply for cross-platform safe replacement: on Windows, running executables cannot be overwritten directly (ERROR_ACCESS_DENIED), so the library renames the old binary before placing the new one. The old binary is hidden rather than deleted on Windows.
newBinaryPath must be readable; currentExePath is the installation target.
func SetTestHooks ¶
func SetTestHooks( check func(ctx context.Context, currentVersion string) (*Release, error), download func(ctx context.Context, currentVersion string, targetPath string) (*Release, error), verifyChecksum func(binaryPath string, release *Release) error, install func(newBinaryPath string, currentExePath string) error, )
SetTestHooks installs deterministic hooks for tests that need to control the update source without network access. Passing nil resets hooks to production.
func VerifyChecksum ¶
VerifyChecksum validates that a downloaded binary exists and the release metadata is present.
Note: the go-selfupdate ChecksumValidator already verifies the SHA256 checksum against checksums.txt during Download via UpdateTo. This function is the explicit post-download verification hook in the three-step flow. For Phase 1, it confirms file existence and non-nil release metadata. Full cryptographic re-verification (re-downloading checksums.txt) is reserved for Phase 3 where the temp path is separate from the install destination.
Types ¶
type ApplyError ¶
ApplyError carries the discovered release when apply/install fails after download.
func (*ApplyError) Error ¶
func (e *ApplyError) Error() string
func (*ApplyError) Unwrap ¶
func (e *ApplyError) Unwrap() error
type Release ¶
type Release struct {
Version string `json:"version"`
AssetName string `json:"asset_name"`
AssetURL string `json:"asset_url"`
ReleaseNotes string `json:"release_notes"`
PublishedAt string `json:"published_at"`
}
Release holds information about an available update.
func ApplyUpdate ¶
ApplyUpdate downloads and installs the latest release, replacing the current executable. Preserved as a backwards-compatible wrapper calling Download → VerifyChecksum → Install.
Phase 3 callers should prefer Download + VerifyChecksum + Install directly to control the download destination and enable the muxcore hot-swap flow.
func ApplyUpdateAt ¶
func ApplyUpdateAt(ctx context.Context, currentVersion string, currentExePath string) (*Release, error)
ApplyUpdateAt downloads and installs the latest release over currentExePath. This variant exists so the upgrade coordinator can hot-swap a known binary path without relying on selfupdate.ExecutablePath().
go-selfupdate's UpdateTo handles the full lifecycle: download, decompress, checksum validation (via ChecksumValidator), and atomic binary replacement (rename old → .old, place new). On Windows, running executables can be renamed but not deleted — go-selfupdate hides the .old file instead of removing it.
func CheckUpdate ¶
CheckUpdate detects the latest release and compares it with the current version. Returns nil release if already up to date or no release found.
func Download ¶
Download detects the latest release and downloads it to targetPath.
Checksum validation is performed by the embedded ChecksumValidator during the UpdateTo call — the file at targetPath is already verified when this function returns successfully.
Returns nil release if currentVersion is already up to date (no download performed). The caller is responsible for cleaning up targetPath on error.
func ReleaseFromError ¶
ReleaseFromError extracts release metadata from an apply error chain.