updatecheck

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package updatecheck provides centralized version checking against GitHub releases.

Index

Constants

View Source
const (
	// DefaultCheckInterval is the default interval between update checks (4 hours).
	DefaultCheckInterval = 4 * time.Hour

	// EnvDisableAutoUpdate disables all update checks when set to "true".
	EnvDisableAutoUpdate = "MCPPROXY_DISABLE_AUTO_UPDATE"

	// EnvAllowPrereleaseUpdates enables prerelease version comparison when set to "true".
	EnvAllowPrereleaseUpdates = "MCPPROXY_ALLOW_PRERELEASE_UPDATES"
)
View Source
const (
	// GitHubRepo is the repository to check for releases
	GitHubRepo = "smart-mcp-proxy/mcpproxy-go"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	// Name is the asset filename (e.g., "mcpproxy-v1.2.3-darwin-arm64.tar.gz")
	Name string `json:"name"`

	// BrowserDownloadURL is the direct download URL
	BrowserDownloadURL string `json:"browser_download_url"`

	// ContentType is the MIME type of the asset
	ContentType string `json:"content_type"`

	// Size is the file size in bytes
	Size int64 `json:"size"`
}

Asset represents a downloadable file attached to a release.

type Checker

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

Checker performs background version checks against GitHub releases.

func New

func New(logger *zap.Logger, version string) *Checker

New creates a new update checker.

func (*Checker) CheckNow

func (c *Checker) CheckNow() *VersionInfo

CheckNow performs an immediate update check against GitHub. This bypasses the periodic check interval and updates the cached version info. Returns the updated VersionInfo after the check completes.

func (*Checker) GetVersionInfo

func (c *Checker) GetVersionInfo() *VersionInfo

GetVersionInfo returns the current version information. Thread-safe.

func (*Checker) SetCheckFunc

func (c *Checker) SetCheckFunc(fn func() (*GitHubRelease, error))

SetCheckFunc sets a custom check function. Primarily for testing.

func (*Checker) SetCheckInterval

func (c *Checker) SetCheckInterval(interval time.Duration)

SetCheckInterval sets the interval between update checks. Primarily for testing.

func (*Checker) Start

func (c *Checker) Start(ctx context.Context)

Start begins the background update checker. It performs an initial check immediately and then checks every checkInterval. The checker respects MCPPROXY_DISABLE_AUTO_UPDATE environment variable.

type GitHubClient

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

GitHubClient handles communication with the GitHub Releases API.

func NewGitHubClient

func NewGitHubClient(logger *zap.Logger) *GitHubClient

NewGitHubClient creates a new GitHub API client.

func (*GitHubClient) GetLatestRelease

func (c *GitHubClient) GetLatestRelease() (*GitHubRelease, error)

GetLatestRelease fetches the latest stable release from GitHub.

func (*GitHubClient) GetLatestReleaseIncludingPrereleases

func (c *GitHubClient) GetLatestReleaseIncludingPrereleases() (*GitHubRelease, error)

GetLatestReleaseIncludingPrereleases fetches the latest release including prereleases.

func (*GitHubClient) GetRelease

func (c *GitHubClient) GetRelease(includePrereleases bool) (*GitHubRelease, error)

GetRelease fetches the appropriate release based on whether prereleases should be included.

type GitHubRelease

type GitHubRelease struct {
	// TagName is the git tag for this release (e.g., "v1.2.3")
	TagName string `json:"tag_name"`

	// Name is the release title
	Name string `json:"name"`

	// Body is the release notes in markdown format
	Body string `json:"body"`

	// Prerelease indicates if this is a prerelease
	Prerelease bool `json:"prerelease"`

	// HTMLURL is the URL to view the release on GitHub
	HTMLURL string `json:"html_url"`

	// PublishedAt is the publication timestamp
	PublishedAt string `json:"published_at"`

	// Assets is the list of downloadable files
	Assets []Asset `json:"assets"`
}

GitHubRelease represents a release from the GitHub Releases API. This matches the structure returned by: - GET /repos/{owner}/{repo}/releases/latest - GET /repos/{owner}/{repo}/releases

type InfoResponseUpdate

type InfoResponseUpdate struct {
	// Available indicates if an update is available
	Available bool `json:"available"`

	// LatestVersion is the latest version (empty if not checked)
	LatestVersion string `json:"latest_version,omitempty"`

	// ReleaseURL is the GitHub release page URL
	ReleaseURL string `json:"release_url,omitempty"`

	// CheckedAt is when the last check occurred
	CheckedAt *time.Time `json:"checked_at,omitempty"`

	// IsPrerelease indicates if latest is a prerelease
	IsPrerelease bool `json:"is_prerelease,omitempty"`

	// CheckError is set if the last check failed
	CheckError string `json:"check_error,omitempty"`
}

InfoResponseUpdate is the update field added to the /api/v1/info response. This structure is serialized to JSON for API responses.

type VersionInfo

type VersionInfo struct {
	// CurrentVersion is the version of the running MCPProxy instance.
	// Format: semver with "v" prefix (e.g., "v1.2.3") or "development"
	CurrentVersion string `json:"current_version"`

	// LatestVersion is the latest version available on GitHub releases.
	// Empty if update check has not completed yet.
	LatestVersion string `json:"latest_version,omitempty"`

	// UpdateAvailable is true if LatestVersion > CurrentVersion.
	// Computed via semver comparison.
	UpdateAvailable bool `json:"available"`

	// ReleaseURL is the URL to the GitHub release page for the latest version.
	ReleaseURL string `json:"release_url,omitempty"`

	// CheckedAt is the timestamp of the last successful update check.
	CheckedAt *time.Time `json:"checked_at,omitempty"`

	// IsPrerelease indicates if the latest version is a prerelease.
	IsPrerelease bool `json:"is_prerelease,omitempty"`

	// CheckError contains the error message if the last check failed.
	// Empty string if no error.
	CheckError string `json:"check_error,omitempty"`
}

VersionInfo represents the current version and update availability. This is stored in-memory only and refreshed on startup + every 4 hours.

func (*VersionInfo) ToAPIResponse

func (v *VersionInfo) ToAPIResponse() *InfoResponseUpdate

ToAPIResponse converts VersionInfo to the API response format.

Jump to

Keyboard shortcuts

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