updatescheck

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package updatescheck polls GitHub's releases API once per day and caches the latest-release status in memory so the webapi layer can serve it without outbound network traffic on the request path.

The package owns one background goroutine (Checker.Run) that honors a configstore-backed toggle and a reload channel for toggle flips. The HTTP handler reads a snapshot under RLock via Snapshot().

Index

Constants

View Source
const (
	StatusDisabled  = "disabled"
	StatusPending   = "pending"
	StatusCurrent   = "current"
	StatusAvailable = "available"
)

Status string values exposed to the webapi layer. Mirrors the enum in design decision D6 so the handler is a pure projection with no business logic.

View Source
const DefaultBaseURL = "https://api.github.com"

DefaultBaseURL is the production GitHub API base. Tests override via NewChecker's baseURL argument to point at an httptest.NewServer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker polls GitHub's releases API and serves the result via Snapshot(). Safe for concurrent use: Run mutates under Lock, Snapshot reads under RLock.

func NewChecker

func NewChecker(version string, store Store, baseURL string, logger *slog.Logger) *Checker

NewChecker constructs a Checker. The version arg is stripped of any -dirty / -beta.N suffix once at construction so Status.Current is always bare MAJOR.MINOR.PATCH, even on dev builds. baseURL is DefaultBaseURL in production; tests pass httptest.Server.URL. logger is optional and falls back to slog.Default().

func (*Checker) Run

func (c *Checker) Run(ctx context.Context, reloadCh <-chan struct{}) error

Run blocks until ctx is cancelled. Safe to call exactly once per Checker. Starts with a short timer for the startup delay, then enters a ticker loop over ctx.Done(), the tick channel, and reloadCh. Both the tick and reload branches call evaluate(), so "check on schedule" and "check on toggle flip" share one code path.

func (*Checker) Snapshot

func (c *Checker) Snapshot() Status

Snapshot returns a copy of the current status under RLock. Safe to call concurrently with Run; the webapi handler calls this on every /api/updates/status request.

type Status

type Status struct {
	Status    string    // one of the Status* constants above
	Current   string    // running version, stripped of -dirty / -beta.N suffixes
	Latest    string    // tag_name from GitHub, stripped of a leading "v"
	URL       string    // html_url from GitHub, unmodified
	CheckedAt time.Time // time of most recent successful check; zero when none yet
}

Status is the publicly-visible shape of the cached check result. Returned by Snapshot() and projected one-to-one into the /api/updates/status response DTO in the webapi layer.

type Store

type Store interface {
	GetUpdatesConfig(ctx context.Context) (configstore.UpdatesConfig, error)
}

Store is the minimal configstore contract this package needs. Kept as an interface so tests don't need a real SQLite DB.

Jump to

Keyboard shortcuts

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