updatecheck

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package updatecheck looks up the latest RD Panel release on GitHub for the About page. Answers are cached (6 h by default; failures are retried after 30 min while the last good answer is kept), so the panel calls the GitHub API at most a few times a day no matter how often the page is opened.

Index

Constants

View Source
const (
	DefaultTTL   = 6 * time.Hour
	DefaultRetry = 30 * time.Minute
)

Defaults of a Checker.

View Source
const DefaultURL = "https://api.github.com/repos/bropines/rdpanel/releases/latest"

DefaultURL is the GitHub "latest release" endpoint of this project.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	URL       string
	UserAgent string
	Client    *http.Client
	TTL       time.Duration // cache lifetime of a successful answer
	Retry     time.Duration // delay before retrying after a failure
	Now       func() time.Time
	// contains filtered or unexported fields
}

Checker fetches and caches the latest release. The zero value is not usable; use New.

func New

func New(userAgent string) *Checker

New returns a Checker for DefaultURL. userAgent identifies the panel to GitHub (its API rejects requests without one).

func (*Checker) Latest

func (c *Checker) Latest(ctx context.Context) Result

Latest returns the cached answer, refreshing it first when it is stale. Concurrent callers wait for one in-flight request (bounded by a 5 s timeout); a cancelled caller does not abort the shared refresh.

type Release

type Release struct {
	Version     string // tag name, e.g. "v0.2.0"
	URL         string // release page
	PublishedAt time.Time
}

Release is a published GitHub release.

type Result

type Result struct {
	// Latest is nil until a check succeeded (or when the repository has no
	// published release yet).
	Latest *Release
	// CheckedAt is the time of the last attempt.
	CheckedAt time.Time
	// Err is the last attempt's error ("" when it succeeded).
	Err string
}

Result is the cached state of the check.

type Status

type Status string

Status compares a running version with the latest release.

const (
	StatusUnknown         Status = "unknown"
	StatusUpToDate        Status = "up_to_date"
	StatusUpdateAvailable Status = "update_available"
)

Status values.

func Compare

func Compare(current, latest string) Status

Compare reports whether latest is newer than current. Both are semantic versions with an optional "v" prefix; current may carry a `git describe` suffix ("v0.1.1-3-gabc1234-dirty"), which counts as that tag. Anything else (e.g. "dev") is StatusUnknown.

Jump to

Keyboard shortcuts

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