update

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRepository = "Taf0711/splice"
	DefaultTimeout    = 5 * time.Second
)
View Source
const DefaultDownloadTimeout = 5 * time.Minute

DefaultDownloadTimeout bounds the archive/checksum download phase of a standalone Apply, separately from Options.Timeout (which only covers the small release-metadata check), so a stalled connection can't hang forever.

View Source
const (
	// NoticeRefreshAfter is the maximum age of a cached update check.
	NoticeRefreshAfter = 24 * time.Hour
)

Variables

This section is empty.

Functions

func CachedNotice added in v0.1.4

func CachedNotice(ctx context.Context, options NoticeOptions) (string, error)

CachedNotice checks for an update at most once per NoticeRefreshAfter. It stores the last result on disk, including failed checks, so a failed or slow network cannot cause repeated work on every startup. Errors are returned to the caller, which can ignore them for a courtesy background check.

func CleanupStaleBinary

func CleanupStaleBinary(targetPath string)

CleanupStaleBinary is a no-op outside Windows, which is the only platform that requires renaming a running binary aside instead of replacing it directly.

func CompareSemver

func CompareSemver(left string, right string) (int, error)

CompareSemver compares two semver-ish release tags.

func Endpoint

func Endpoint(repository string) string

Endpoint returns the GitHub latest-release API endpoint for a repository.

func Format

func Format(result Result) string

func FormatApply

func FormatApply(result ApplyResult) string

FormatApply renders an ApplyResult as human-readable text.

func FormatNotice added in v0.1.4

func FormatNotice(result Result, method InstallMethod) string

FormatNotice returns the single-line notice shown on stderr for a newer release. It uses npm for npm-managed installs and the standalone command for all other installs.

func NormalizeVersionTag

func NormalizeVersionTag(version string) (string, error)

NormalizeVersionTag returns a comparable x.y.z version from a release tag.

func NoticeDisabled added in v0.1.4

func NoticeDisabled() bool

NoticeDisabled reports whether background update notices are disabled.

func ResolveEndpoint

func ResolveEndpoint(endpointOrRepository string, repository string) (string, error)

ResolveEndpoint resolves a URL or owner/repo slug into a release API endpoint.

func UpdatesDisabled added in v0.1.4

func UpdatesDisabled() bool

UpdatesDisabled reports whether all update behavior is disabled.

Types

type ApplyResult

type ApplyResult struct {
	Result
	Applied       bool          `json:"applied"`
	InstallMethod InstallMethod `json:"installMethod,omitempty"`
	BinaryPath    string        `json:"binaryPath,omitempty"`
	Message       string        `json:"message,omitempty"`
	Warnings      []string      `json:"warnings,omitempty"`
}

ApplyResult reports the outcome of Apply.

func Apply

func Apply(ctx context.Context, options Options) (ApplyResult, error)

Apply checks for an update and, if one is available, installs it: via `npm install -g` for npm-managed installs, or by downloading, verifying, and atomically replacing the binary for standalone installs.

type Asset

type Asset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url,omitempty"`
}

type AssetCheck

type AssetCheck struct {
	Platform      string `json:"platform"`
	Arch          string `json:"arch"`
	ArchiveName   string `json:"archiveName"`
	ArchiveURL    string `json:"archiveUrl,omitempty"`
	ChecksumName  string `json:"checksumName"`
	ChecksumURL   string `json:"checksumUrl,omitempty"`
	ArchiveFound  bool   `json:"archiveFound"`
	ChecksumFound bool   `json:"checksumFound"`
	Verified      bool   `json:"verified"`
}

type InstallMethod

type InstallMethod string

InstallMethod identifies how the running splice binary was installed.

const (
	InstallMethodNpm        InstallMethod = "npm"
	InstallMethodStandalone InstallMethod = "standalone"
)

func DetectInstallMethod

func DetectInstallMethod(executablePath string) InstallMethod

DetectInstallMethod inspects the directory containing executablePath for npm-install markers left by scripts/postinstall.mjs.

type NoticeOptions added in v0.1.4

type NoticeOptions struct {
	// Check overrides Check. It is used by tests and by the CLI dependency seam.
	Check   func(context.Context, Options) (Result, error)
	Options Options
	// ExecutablePath is used to select the update command for the install method.
	ExecutablePath string
	// Now overrides the clock. A nil value uses time.Now.
	Now func() time.Time
	// CachePath overrides the user cache path. An empty value uses the default path
	// or SPLICE_UPDATE_CACHE_PATH when set.
	CachePath string
}

NoticeOptions configures a cached background update check.

type Options

type Options struct {
	CurrentVersion string
	// Endpoint accepts a full release API URL, an owner/repo slug, or a data:
	// endpoint for deterministic tests.
	Endpoint   string
	Repository string
	Timeout    time.Duration
	GOOS       string
	GOARCH     string
	// Fetch overrides the release fetcher for tests and alternate transports.
	Fetch func(context.Context, string) (Release, error)
}

Options configures a release update check.

type Release

type Release struct {
	TagName string  `json:"tag_name"`
	HTMLURL string  `json:"html_url"`
	Assets  []Asset `json:"assets"`
}

type Result

type Result struct {
	CurrentVersion  string     `json:"currentVersion"`
	LatestVersion   string     `json:"latestVersion"`
	ReleaseURL      string     `json:"releaseUrl"`
	TagName         string     `json:"tagName"`
	ReleaseAsset    AssetCheck `json:"releaseAsset"`
	UpdateAvailable bool       `json:"updateAvailable"`
}

func Check

func Check(ctx context.Context, options Options) (Result, error)

type Target

type Target struct {
	Name     string `json:"name"`
	GOOS     string `json:"goos"`
	GOARCH   string `json:"goarch"`
	Platform string `json:"platform"`
	Arch     string `json:"arch"`
}

Target identifies a supported release archive target.

func ResolveTarget

func ResolveTarget(target string) (Target, error)

ResolveTarget maps a release target name like windows-x64 to Go build coordinates and release asset naming fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL