update

package
v0.0.0-...-8f9dc6d Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRepo    = "CGuiho/mirror"
	DefaultBaseURL = "https://api.github.com"
)
View Source
const CacheMaxAge = 24 * time.Hour
View Source
const (
	WorkerEnvVar = "MIRROR_UPDATE_WORKER"
)

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(v1, v2 string) int

func DefaultCachePath

func DefaultCachePath() (string, error)

DefaultCachePath returns ~/.guiho/mirror/cache.json.

func IsExpired

func IsExpired(cache *CacheData, ttl time.Duration) bool

func IsExpiredAt

func IsExpiredAt(cache *CacheData, ttl time.Duration, now time.Time) bool

func LaunchBackgroundWorker

func LaunchBackgroundWorker(execPath, currentVersion string, opts CatalogOptions) error

func ReadNotice

func ReadNotice(currentVersion string, now time.Time) string

ReadNotice is foreground-safe: it performs local file IO only.

func RunLeasedWorker

func RunLeasedWorker(ctx context.Context, currentVersion string, opts CatalogOptions, cachePath, leasePath, token string) error

func RunWorker

func RunWorker(ctx context.Context, currentVersion string, opts CatalogOptions, cachePath string) error

func SaveCache

func SaveCache(path string, cache *CacheData) error

SaveCache atomically writes cache data without a predictable shared temp path.

func VersionFromTag

func VersionFromTag(tag string) (string, bool)

Types

type CacheData

type CacheData struct {
	LatestVersion   string    `json:"latestVersion"`
	CurrentVersion  string    `json:"currentVersion"`
	LastCheck       time.Time `json:"lastCheck"`
	ReleaseURL      string    `json:"releaseUrl"`
	UpdateAvailable bool      `json:"updateAvailable"`
	ReleaseNotes    string    `json:"releaseNotes,omitempty"`
}

CacheData is the validated, local-only result of the last update check.

func LoadCache

func LoadCache(path string) (*CacheData, error)

LoadCache strictly reads the owned cache contract. A missing cache is not an error; corrupt data is returned as an error so callers can treat it as a miss.

type CatalogOptions

type CatalogOptions struct {
	BaseURL    string
	HTTPClient *http.Client
	Repo       string
}

type Release

type Release struct {
	TagName     string         `json:"tag_name"`
	Name        string         `json:"name"`
	PublishedAt time.Time      `json:"published_at"`
	HTMLURL     string         `json:"html_url"`
	Body        string         `json:"body"`
	Prerelease  bool           `json:"prerelease"`
	Draft       bool           `json:"draft"`
	Assets      []ReleaseAsset `json:"assets"`
	Version     string         `json:"-"`
}

func FetchLatestRelease

func FetchLatestRelease(ctx context.Context, opts CatalogOptions) (*Release, error)

func FetchReleases

func FetchReleases(ctx context.Context, opts CatalogOptions) ([]Release, error)

FetchReleases exhausts the GitHub catalog, retains only canonical mirror/vX.Y.Z tags, deduplicates by tag, and sorts by semantic version.

type ReleaseAsset

type ReleaseAsset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
	Size               int64  `json:"size"`
}

Jump to

Keyboard shortcuts

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