Documentation
¶
Overview ¶
Package version exposes the build-time version metadata of the drift binary and the self-upgrade workflow.
The Version, Commit and BuildDate variables are intended to be set via -ldflags at build time:
go build -ldflags "\ -X github.com/Alei-001/drift/internal/version.Version=v0.1.0 \ -X github.com/Alei-001/drift/internal/version.Commit=$(git rev-parse --short HEAD) \ -X github.com/Alei-001/drift/internal/version.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ ./cmd/drift
When unset (e.g. a plain `go build` or `go install` without ldflags), Info falls back to runtime/debug.ReadBuildInfo, which for `go install`-built binaries carries the module version and VCS revision.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNetwork = errors.New("network error") ErrNoRelease = errors.New("no release available") ErrNoAsset = errors.New("no matching release asset") ErrChecksumMismatch = errors.New("checksum verification failed") )
ErrNetwork, ErrNoRelease, ErrNoAsset, ErrChecksumMismatch are sentinel-like errors returned by Upgrade. The CLI inspects them with errors.Is to tailor the user hint. ErrChecksumMismatch is wrapped by the checksum verification path both when the published checksum does not match the downloaded asset and when the checksums file is malformed and cannot be parsed — both cases mean verification failed and the upgrade must be aborted (fail-closed).
var ( Version = "(devel)" Commit = "unknown" BuildDate = "unknown" )
Build-time variables. Overridable via -ldflags "-X ...=value".
Functions ¶
func CompareVersions ¶
CompareVersions compares two version strings. Returns -1, 0, 1 if a is less than, equal to, or greater than b. Returns an error wrapping errInvalidVersion if either string is not a recognizable semver.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
Size int64 `json:"size"`
}
Asset describes a single downloadable file attached to a release.
type Info ¶
type Info struct {
Version string `json:"version"`
Commit string `json:"commit"`
Built string `json:"built"`
GoVersion string `json:"go_version"`
OS string `json:"os"`
Arch string `json:"arch"`
}
Info describes the running binary.
func GetInfo ¶
func GetInfo() Info
GetInfo returns the version metadata of the running binary, enriched with the toolchain and platform. When the ldflags-injected Version is the default "(devel)" placeholder, it is replaced with the module version reported by runtime/debug.ReadBuildInfo (if any) so that `go install`-built binaries still report a meaningful version.
func (Info) IsDevel ¶
IsDevel reports whether the binary is an unreleased development build. Only the literal "(devel)" placeholder or a Go pseudo-version of the form "v0.0.0-<timestamp>-<hash>" (emitted by `go install` of a non-tagged commit) is treated as development. A real release tagged "v0.0.0" is NOT a development build.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
Name string `json:"name"`
HTMLURL string `json:"html_url"`
Assets []Asset `json:"assets"`
}
Release describes the subset of GitHub release metadata drift consumes.
type Result ¶
type Result struct {
FromVersion string
ToVersion string
Upgraded bool // true when the binary was actually replaced
Message string // human-readable detail
}
Result summarizes the outcome of an Upgrade call.
func Upgrade ¶
Upgrade checks for a newer drift release on GitHub and, when available, downloads the matching binary and atomically replaces the running executable. Set Check=true to only report the latest version without modifying anything. Set Force=true to reinstall the same version.
On success Result.Upgraded is true when the binary was replaced, false when already up to date (or Check-only). A non-nil error is returned for network, release-matching, download, checksum, extraction, or replacement failures; the CLI maps these to user-facing hints via errors.Is.
type UpgradeOptions ¶
type UpgradeOptions struct {
Check bool // only check for a newer release, do not replace the binary
Force bool // replace even when already up to date
APIURL string // override GitHub API base (for tests); defaults to https://api.github.com
ProgressWriter io.Writer // optional progress bar output (nil = no progress)
}
UpgradeOptions controls the behaviour of Upgrade.