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
- func CompareVersions(v1, v2 string) int
- func RegisterRoutes(apiAuth, apiV1 *swagger.RouteGroup, h *Handler)
- type Checker
- type ConfigInfo
- type ConfigInfoResponse
- type Handler
- type HealthInfoResponse
- type LatestVersionInfo
- type LatestVersionResponse
- type NpmPackage
- type VersionInfo
- type VersionInfoResponse
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.
func RegisterRoutes ¶
func RegisterRoutes(apiAuth, apiV1 *swagger.RouteGroup, h *Handler)
RegisterRoutes wires the /info/* endpoints onto the given route groups. apiAuth receives routes that need no authentication (health check). apiV1 receives the authenticated info routes.
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.
func (*Handler) GetHealthInfo ¶
GetHealthInfo is a lightweight health check that can be called frequently.
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.
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"`
}
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 VersionInfo ¶
type VersionInfo struct {
Version string `json:"version" example:"1.0.0"`
}
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.