info

package
v0.260813.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MPL-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	GithubReleases = "https://github.com/tingly-dev/tingly-box/releases"
)

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(v1, v2 string) int

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

func (c *Checker) CheckLatestVersion() (version, releaseURL string, err error)

CheckLatestVersion returns the latest published version with a fallback strategy:

  1. npm registry (primary)
  2. 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

func NewHandler(version, configFile, configDir string) *Handler

NewHandler creates a Handler.

func (*Handler) GetHealthInfo

func (h *Handler) GetHealthInfo(c *gin.Context)

GetHealthInfo is a lightweight health check that can be called frequently.

func (*Handler) GetInfoConfig

func (h *Handler) GetInfoConfig(c *gin.Context)

GetInfoConfig returns the runtime configuration paths.

func (*Handler) GetInfoVersion

func (h *Handler) GetInfoVersion(c *gin.Context)

GetInfoVersion returns the current running version.

func (*Handler) GetLatestVersion

func (h *Handler) GetLatestVersion(c *gin.Context)

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.

Jump to

Keyboard shortcuts

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