Help us shape the future of Go! Take the 2026 Go Developer Survey

updatechecker

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package updatechecker finds newer gitsss releases and verifies downloaded packages.

Index

Constants

View Source
const (
	// DefaultGitHubRepo is the release source checked by the CLI and admin UI.
	DefaultGitHubRepo = "neko233-com/gitsss"
	// DefaultMirror is a public prefix proxy that stays reachable from many
	// networks in mainland China when api.github.com does not. Replace it
	// with an internal mirror when one exists.
	DefaultMirror = "https://ghfast.top"
)

Variables

This section is empty.

Functions

func GetNeedUpdate

func GetNeedUpdate(ctx context.Context) bool

GetNeedUpdate returns true whether a newer version of gitsss is available.

func GetRemoteVersion

func GetRemoteVersion(ctx context.Context) string

GetRemoteVersion returns the current remote version (or currently installed version if fail to fetch from DB)

func GitSSSUpdateChecker

func GitSSSUpdateChecker(ctx context.Context, httpEndpoint string) error

GitSSSUpdateChecker records the version from an explicitly configured manifest endpoint. An empty endpoint performs no network request, including when the cron task is enabled.

func MirrorText added in v1.2.0

func MirrorText(mirrors []string) string

MirrorText renders mirrors one per line for the admin form.

func ParseMirrors added in v1.2.0

func ParseMirrors(text string) ([]string, error)

ParseMirrors splits a comma, semicolon, or newline separated mirror list.

func SaveReport added in v1.2.0

func SaveReport(ctx context.Context, report Report) error

SaveReport stores the latest check for the admin page.

func SaveSettings added in v1.2.0

func SaveSettings(settings Settings) error

SaveSettings writes mirror settings back to app.ini and the live config. HTTP_ENDPOINT is preserved.

func UpdateRemoteVersion

func UpdateRemoteVersion(ctx context.Context, version string) (err error)

UpdateRemoteVersion updates the latest available version of gitsss.

Types

type Asset added in v1.2.0

type Asset struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256,omitempty"`
}

Asset is one file attached to a gitsss release.

func SelectAsset added in v1.2.0

func SelectAsset(assets []Asset, explicit, goos, goarch string) (Asset, error)

SelectAsset picks an explicit asset name or the best match for this OS and architecture.

type CheckerState

type CheckerState struct {
	LatestVersion string
}

CheckerState stores the remote version from the JSON endpoint

func (*CheckerState) Name

func (r *CheckerState) Name() string

Name returns the name of the state item for update checker

type DownloadResult added in v1.2.0

type DownloadResult struct {
	Report   Report `json:"report"`
	Asset    string `json:"asset"`
	Output   string `json:"output"`
	SHA256   string `json:"sha256"`
	Bytes    int64  `json:"bytes"`
	Verified bool   `json:"verified"`
	Source   string `json:"source"`
}

DownloadResult is the machine-readable result of a verified package download.

func Download added in v1.2.0

func Download(ctx context.Context, opts Options, assetName, output string) (DownloadResult, error)

Download fetches one release asset and refuses to keep it unless the sha256 matches the selected manifest. Reachable sources are tried from lowest latency to highest.

type Options added in v1.2.0

type Options struct {
	HTTPEndpoint    string
	CheckGitHub     bool
	GitHubRepo      string
	Mirrors         []string
	ProbeTimeout    time.Duration
	DownloadTimeout time.Duration
	CurrentVersion  string
}

Options selects where a check looks for the latest gitsss release. An empty mirror list uses DefaultMirror when GitHub checking is enabled. Direct api.github.com is always probed alongside those mirrors.

func OptionsFromConfig added in v1.2.0

func OptionsFromConfig() Options

OptionsFromConfig reads the update checker section from the loaded config. CHECK_GITHUB stays false when the key is absent, so startup does not contact GitHub.

type Probe added in v1.2.0

type Probe struct {
	Name       string `json:"name"`
	Kind       string `json:"kind"`
	URL        string `json:"url"`
	Mirror     string `json:"mirror,omitempty"`
	OK         bool   `json:"ok"`
	LatencyMS  int64  `json:"latency_ms"`
	StatusCode int    `json:"status_code,omitempty"`
	Error      string `json:"error,omitempty"`
	Selected   bool   `json:"selected"`
}

Probe is one availability and latency sample.

type Report added in v1.2.0

type Report struct {
	OK              bool     `json:"ok"`
	Error           string   `json:"error,omitempty"`
	CurrentVersion  string   `json:"current_version,omitempty"`
	LatestVersion   string   `json:"latest_version,omitempty"`
	NeedUpdate      bool     `json:"need_update"`
	HTMLURL         string   `json:"html_url,omitempty"`
	ManifestSource  string   `json:"manifest_source,omitempty"`
	ManifestKind    string   `json:"manifest_kind,omitempty"`
	ManifestTrusted bool     `json:"manifest_trusted"`
	SelectedMirror  string   `json:"selected_mirror,omitempty"`
	Note            string   `json:"note,omitempty"`
	DownloadOrder   []string `json:"download_order,omitempty"`
	Assets          []Asset  `json:"assets,omitempty"`
	Probes          []Probe  `json:"probes"`
	CheckedAt       string   `json:"checked_at"`
}

Report is the machine-readable result of an update check.

func Check added in v1.2.0

func Check(ctx context.Context, opts Options) (Report, error)

Check probes the configured sources and returns the newest release it could read. Direct GitHub is preferred as the manifest when it answers, even if a mirror is faster. Mirrors are then used, fastest first, to download assets that must match that manifest.

func LoadReport added in v1.2.0

func LoadReport(ctx context.Context) (Report, bool)

LoadReport returns the last stored check, if one exists.

type ReportState added in v1.2.0

type ReportState struct {
	Report Report `json:"report"`
}

ReportState stores the last check in the application state table.

func (*ReportState) Name added in v1.2.0

func (r *ReportState) Name() string

Name returns the app-state key for the last update report.

type Settings added in v1.2.0

type Settings struct {
	Mirrors     []string
	GitHubRepo  string
	CheckGitHub bool
	Enabled     *bool
}

Settings is the persisted [cron.update_checker] mirror configuration. A nil Enabled pointer leaves the existing schedule flag untouched.

Jump to

Keyboard shortcuts

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