updater

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package updater checks for new Roger releases and self-updates the binary.

Index

Constants

This section is empty.

Variables

View Source
var (
	GitHubOwner = "EMSERO"
	GitHubRepo  = "roger"
)

GitHubOwner and GitHubRepo are the GitHub coordinates for release checks.

View Source
var StateDir string

StateDir can be set to override where update state is stored. If empty, falls back to ~/.roger/state/ (legacy).

Functions

func AssetName

func AssetName(version string) string

AssetName returns the expected asset filename for the current platform.

func FindAsset

func FindAsset(rel *Release) (string, error)

FindAsset returns the download URL for the current platform's asset.

func FindChecksums

func FindChecksums(rel *Release) (string, error)

FindChecksums returns the download URL for checksums.txt.

func IsNewer

func IsNewer(current, available string) bool

IsNewer returns true if the available version is newer than current. Compares semver strings (v0.4.0 > v0.3.0). Falls back to string comparison.

func Rollback

func Rollback() error

Rollback restores the previous binary from the .bak file created during updates.

func SaveState

func SaveState(s *CheckState) error

SaveState writes the check state to disk.

func ShouldCheck

func ShouldCheck(s *CheckState, interval time.Duration) bool

ShouldCheck returns true if enough time has elapsed since the last check.

func StartupCheck

func StartupCheck(ctx context.Context, currentVersion string) <-chan string

StartupCheck runs a non-blocking background version check. Returns a channel that receives a message if an update is available.

func Update

func Update(ctx context.Context, currentVersion string) (string, error)

Update downloads the latest release and replaces the running binary.

Types

type Asset

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

Asset is a single file attached to a GitHub release.

type CheckState

type CheckState struct {
	LastCheckedAt        time.Time `json:"lastCheckedAt"`
	LastAvailableVersion string    `json:"lastAvailableVersion"`
	LastNotifiedVersion  string    `json:"lastNotifiedVersion"`
}

CheckState persists the last version check result.

func LoadState

func LoadState() (*CheckState, error)

LoadState reads the last check state from disk.

type Release

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

Release holds parsed info from a GitHub release.

func CheckLatest

func CheckLatest(ctx context.Context) (*Release, error)

CheckLatest fetches the latest release from GitHub.

Jump to

Keyboard shortcuts

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