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 ¶
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.
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 ¶
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 ¶
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.
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.