Documentation
¶
Overview ¶
Package versioncheck provides version lookup against the npm registry (with npmmirror as a China-mirror fallback) and semver-style comparison. It is intentionally stateless beyond a short-lived in-memory cache so that it can be wired into any HTTP handler without server-level dependencies.
Package versioncheck exposes the /info/* HTTP endpoints (health, config, version, and latest-version check). Version lookup itself is delegated to Checker; this file only handles request/response wiring.
Index ¶
Constants ¶
const (
GithubReleases = "https://github.com/tingly-dev/tingly-box/releases"
)
Variables ¶
This section is empty.
Functions ¶
func CompareVersions ¶
CompareVersions compares two version strings. Returns 1 if v1 > v2, -1 if v1 < v2, 0 if equal. Handles semver prerelease precedence, date-based (YYMMDD.HHMM), and mixed formats.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker handles version-related operations.
func New ¶
func New() *Checker
New creates a new Checker with default settings (10 s HTTP timeout, 2 h cache TTL).
func (*Checker) CheckLatestVersion ¶
CheckLatestVersion returns the latest published version with a fallback strategy:
- npm registry (primary)
- npmmirror (China mirror)
Results are cached for 2 hours to avoid hammering the registry.
type ConfigInfo ¶
type ConfigInfo struct {
ConfigPath string `json:"config_path" example:"/Users/user/.tingly-box/config.json"`
ConfigDir string `json:"config_dir" example:"/Users/user/.tingly-box"`
}
ConfigInfo holds configuration path information.
type ConfigInfoResponse ¶
type ConfigInfoResponse struct {
Success bool `json:"success" example:"true"`
Data ConfigInfo `json:"data"`
}
ConfigInfoResponse is the JSON envelope for GET /info/config.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler carries the minimal server state needed to serve /info/* endpoints.
func NewHandler ¶
NewHandler creates a Handler. LaunchSource is how this process was itself invoked (see server.WithLaunchSource) — known once at boot, never detected or persisted. InstanceToken is the readiness handshake described on Options.
func (*Handler) GetHealthInfo ¶
GetHealthInfo is a lightweight health check that can be called frequently. It also carries the instance handshake headers: the launcher that started this process requires its token back before it will announce the URL.
func (*Handler) GetInfoConfig ¶
GetInfoConfig returns the runtime configuration paths.
func (*Handler) GetInfoVersion ¶
GetInfoVersion returns the current running version.
func (*Handler) GetLatestVersion ¶
GetLatestVersion checks the npm registry for the latest published version and compares it with the running version.
func (*Handler) RegisterRoutes ¶ added in v1.261002.1
RegisterRoutes wires the /info/* endpoints onto the route groups. Public receives routes that need no authentication (health check). V1 receives the authenticated info routes.
type HealthInfoResponse ¶
type HealthInfoResponse struct {
Status string `json:"status" example:"healthy"`
Service string `json:"service" example:"tingly-box"`
Health bool `json:"health" example:"true"`
}
HealthInfoResponse is the JSON envelope for GET /info/health.
type LatestVersionInfo ¶
type LatestVersionInfo struct {
CurrentVersion string `json:"current_version" example:"0.260124.1430"`
LatestVersion string `json:"latest_version" example:"0.260130.1200"`
HasUpdate bool `json:"has_update" example:"true"`
ReleaseURL string `json:"release_url" example:"https://github.com/tingly-dev/tingly-box/releases"`
ShouldNotify bool `json:"should_notify" example:"true"`
// LaunchSource is how this process was itself invoked; see VersionInfo.
// The update panel uses it to default its method picker (npx/npm/docker)
// to whichever channel matches this install.
LaunchSource string `json:"launch_source" example:"npx"`
}
LatestVersionInfo contains version comparison results.
type LatestVersionResponse ¶
type LatestVersionResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Data LatestVersionInfo `json:"data,omitempty"`
}
LatestVersionResponse is the JSON envelope for GET /info/version/check.
type NpmPackage ¶
type NpmPackage struct {
Name string `json:"name"`
DistTags struct {
Latest string `json:"latest"`
} `json:"dist-tags"`
}
NpmPackage represents an npm registry package response.
type Options ¶ added in v1.261203.0
type Options struct {
Version string
ConfigFile string
ConfigDir string
LaunchSource string
// InstanceToken, when non-empty, is echoed on the health endpoint so a
// launcher can tell this instance from an older one still answering on
// the same port (see server.WithInstanceToken).
InstanceToken string
}
Options carries the per-process metadata the /info/* handlers report.
type VersionInfo ¶
type VersionInfo struct {
Version string `json:"version" example:"1.0.0"`
// LaunchSource is how this process was itself invoked ("binary", "npx",
// "npm"; "" if unknown). The frontend uses it
// to default multi-method pickers (update instructions, quick-start
// commands) to whichever method matches how the user is already running
// Tingly Box. See .design/shortcut.md.
LaunchSource string `json:"launch_source" example:"npx"`
}
VersionInfo holds the running version string.
type VersionInfoResponse ¶
type VersionInfoResponse struct {
Success bool `json:"success" example:"true"`
Message string `json:"message,omitempty"`
Data VersionInfo `json:"data"`
}
VersionInfoResponse is the JSON envelope for GET /info/version.