Documentation
¶
Index ¶
- Constants
- func GetStartTime() time.Time
- func GetUptime() time.Duration
- func IsNewerVersionString(current, target string) bool
- type Applier
- type ApplyRequest
- type Config
- type Downloader
- type Executor
- type GitHubClient
- func (c *GitHubClient) GetDownloadURL(version string) string
- func (c *GitHubClient) GetLatestVersion(ctx context.Context, channel string) (*Version, error)
- func (c *GitHubClient) GetReleaseNotes(ctx context.Context, version string) (string, error)
- func (c *GitHubClient) ListVersions(ctx context.Context) ([]*Version, error)
- type GitHubContent
- type Handler
- func (h *Handler) Apply(c echo.Context) error
- func (h *Handler) ApplyUpdate() error
- func (h *Handler) Check(c echo.Context) error
- func (h *Handler) CheckForUpdate(ctx context.Context) (*UpdateInfo, error)
- func (h *Handler) Download(c echo.Context) error
- func (h *Handler) DownloadOTA(c echo.Context) error
- func (h *Handler) GetCurrentVersion() string
- func (h *Handler) GetStatus() *UpdateStatus
- func (h *Handler) History(c echo.Context) error
- func (h *Handler) Info(c echo.Context) error
- func (h *Handler) LoadHistory(path string) error
- func (h *Handler) OTAStatus(c echo.Context) error
- func (h *Handler) RegisterRoutes(g *echo.Group)
- func (h *Handler) ReleaseNotes(c echo.Context) error
- func (h *Handler) Rollback(c echo.Context) error
- func (h *Handler) SetOTAChecker(ota *OTAChecker)
- func (h *Handler) SetResumeRecoverer(recoverer ResumeRecoverer)
- func (h *Handler) StartAutoUpdater(parent context.Context)
- func (h *Handler) StartDownload(ctx context.Context) error
- type OTAChecker
- type OTAResponse
- type ReleaseInfo
- type ResumeRecoverInput
- type ResumeRecoverer
- type ResumeRecovery
- type UpdateHistory
- type UpdateInfo
- type UpdateStatus
- type Version
Constants ¶
const ( OnlineURL = "https://ota.zimaos.com" OnlineFallbackURL = "https://ota2.zimaos.com" OnlineFallbackIP = "http://139.224.8.35" OnlineFallbackHeader = "ota2.zimaos.com" )
const ( StateIdle = "idle" StateChecking = "checking" StateDownloading = "downloading" StateApplying = "applying" StateRestarting = "restarting" StateFailed = "failed" )
Update state constants
const ( StatusSuccess = "success" StatusFailed = "failed" StatusRolledBack = "rolled_back" )
History status constants
const ( ChannelStable = "stable" ChannelBeta = "beta" ChannelAlpha = "alpha" )
Release channel constants
Variables ¶
This section is empty.
Functions ¶
func GetStartTime ¶
GetStartTime returns the service start time (preserved across hot updates)
func IsNewerVersionString ¶
IsNewerVersionString compares two version strings, returns true if target > current.
Types ¶
type Applier ¶
type Applier struct {
// contains filtered or unexported fields
}
Applier handles applying updates
func NewApplier ¶
NewApplier creates a new update applier
func (*Applier) Apply ¶
Apply applies the downloaded update (backup + replace + exec). Note: on success the process is replaced and this never returns.
func (*Applier) PrepareAndReplace ¶
PrepareAndReplace backs up the current binary and replaces it with the new one. Does NOT restart — call Restart() separately when ready. On Windows, if the binary is locked (running process), the new binary is saved as .new and the bat-script-based exec() will handle the swap after exit.
func (*Applier) Restart ¶
Restart replaces the current process with the new binary. On Unix this calls syscall.Exec (never returns on success). On Windows this spawns a new process and exits.
func (*Applier) SetExecutor ¶
SetExecutor overrides the default platform executor (for testing).
type ApplyRequest ¶
type ApplyRequest struct {
ResumeContext map[string]interface{} `json:"resume_context,omitempty"`
ResumeDelaySeconds int `json:"resume_delay_seconds,omitempty"`
}
ApplyRequest supports optional resume context persistence before restart. Clients can send contextual payload so the new process can recover unfinished work.
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"`
CheckInterval time.Duration `yaml:"check_interval"`
AutoDownload bool `yaml:"auto_download"`
AutoApply bool `yaml:"auto_apply"`
ReleaseChannel string `yaml:"release_channel"`
BackupCount int `yaml:"backup_count"`
StoragePath string `yaml:"storage_path"`
}
Config holds update configuration
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader handles binary downloads
func NewDownloader ¶
func NewDownloader(storagePath string) *Downloader
NewDownloader creates a new downloader
func (*Downloader) Progress ¶
func (d *Downloader) Progress() float64
Progress returns current download progress
func (*Downloader) SetProgressCallback ¶
func (d *Downloader) SetProgressCallback(fn func(float64))
SetProgressCallback sets the progress callback
type GitHubClient ¶
type GitHubClient struct {
// contains filtered or unexported fields
}
GitHubClient handles version discovery from GitHub
func NewGitHubClient ¶
func NewGitHubClient() *GitHubClient
NewGitHubClient creates a new GitHub client
func (*GitHubClient) GetDownloadURL ¶
func (c *GitHubClient) GetDownloadURL(version string) string
GetDownloadURL returns the download URL for a specific version
func (*GitHubClient) GetLatestVersion ¶
GetLatestVersion returns the latest version for a given channel
func (*GitHubClient) GetReleaseNotes ¶
GetReleaseNotes fetches release notes for a version
func (*GitHubClient) ListVersions ¶
func (c *GitHubClient) ListVersions(ctx context.Context) ([]*Version, error)
ListVersions lists all available versions from release-note directory
type GitHubContent ¶
type GitHubContent struct {
Name string `json:"name"`
Type string `json:"type"`
Path string `json:"path"`
}
GitHubContent represents GitHub API content response
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles update API endpoints
func NewHandler ¶
NewHandler creates a new update handler
func (*Handler) Apply ¶
The response is sent BEFORE the process is replaced, so the client should start polling /api/v1/health to detect when the new version is up.
func (*Handler) ApplyUpdate ¶
ApplyUpdate applies the downloaded update.
func (*Handler) CheckForUpdate ¶
func (h *Handler) CheckForUpdate(ctx context.Context) (*UpdateInfo, error)
CheckForUpdate checks for available updates and returns the info.
func (*Handler) DownloadOTA ¶
DownloadOTA downloads the update from OTA package URLs (with mirror fallback). POST /api/v1/system/update/download-ota
func (*Handler) GetCurrentVersion ¶
GetCurrentVersion returns the current version string.
func (*Handler) GetStatus ¶
func (h *Handler) GetStatus() *UpdateStatus
GetStatus returns the current update status.
func (*Handler) LoadHistory ¶
LoadHistory loads history from file
func (*Handler) OTAStatus ¶
OTAStatus returns the latest OTA check result. GET /api/v1/system/update/ota?desktop=1
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers update routes
func (*Handler) ReleaseNotes ¶
ReleaseNotes fetches release notes content via the downloader (GitHub URL expansion + IPv4 fallback). GET /api/v1/system/update/release-notes
func (*Handler) SetOTAChecker ¶
func (h *Handler) SetOTAChecker(ota *OTAChecker)
SetOTAChecker attaches the background OTA checker to the handler.
func (*Handler) SetResumeRecoverer ¶
func (h *Handler) SetResumeRecoverer(recoverer ResumeRecoverer)
SetResumeRecoverer sets the callback used to restore workloads after OTA restart.
func (*Handler) StartAutoUpdater ¶
StartAutoUpdater starts background auto-update checks when enabled. It is a no-op unless update.enabled and one of auto_download/auto_apply is true.
type OTAChecker ¶
type OTAChecker struct {
// contains filtered or unexported fields
}
OTAChecker performs periodic update checks against the OTA server.
func NewOTAChecker ¶
func NewOTAChecker(version, dataDir, lang string) *OTAChecker
NewOTAChecker creates a new OTA checker.
func (*OTAChecker) FetchForDesktop ¶
func (o *OTAChecker) FetchForDesktop(ctx context.Context) (*OTAResponse, error)
FetchForDesktop performs an OTA check with the -desktop OS suffix.
func (*OTAChecker) GetLatest ¶
func (o *OTAChecker) GetLatest() *OTAResponse
GetLatest returns the latest OTA response, if any.
func (*OTAChecker) Run ¶
func (o *OTAChecker) Run(ctx context.Context)
Run starts the OTA check loop. Intended to be called via lifecycle manager.
func (*OTAChecker) UpdateAvailable ¶
func (o *OTAChecker) UpdateAvailable() bool
UpdateAvailable returns true if a newer version is available.
type OTAResponse ¶
type OTAResponse struct {
Version string `json:"version"`
Packages []string `json:"packages"`
ReleaseNoteURL string `json:"release_note_url"`
Delay int `json:"delay,omitempty"` // cooldown seconds before allowing update
}
OTAResponse is the JSON response from the OTA server (BlueReleaseInfo).
type ReleaseInfo ¶
type ReleaseInfo struct {
Version string `json:"version"`
Channel string `json:"channel"` // stable, beta, alpha
DownloadURL string `json:"download_url"`
Checksum string `json:"checksum"`
Size int64 `json:"size"`
Notes string `json:"notes"`
PublishedAt time.Time `json:"published_at"`
}
ReleaseInfo represents a release from GitHub
type ResumeRecoverInput ¶
type ResumeRecoverInput struct {
TaskID string `json:"task_id"`
FromVersion string `json:"from_version"`
TargetVersion string `json:"target_version,omitempty"`
CurrentVersion string `json:"current_version"`
Context map[string]interface{} `json:"context,omitempty"`
}
ResumeRecoverInput carries persisted OTA resume context into an external recoverer.
type ResumeRecoverer ¶
type ResumeRecoverer func(ctx context.Context, input ResumeRecoverInput) error
ResumeRecoverer executes post-restart recovery using persisted resume context.
type ResumeRecovery ¶
type ResumeRecovery struct {
TaskID string `json:"task_id"`
Status string `json:"status"` // success, failed
FromVersion string `json:"from_version"`
TargetVersion string `json:"target_version"`
CurrentVersion string `json:"current_version"`
RecoveredAt time.Time `json:"recovered_at"`
Context map[string]interface{} `json:"context,omitempty"`
Error string `json:"error,omitempty"`
}
ResumeRecovery reports the latest one-time post-restart recovery execution.
type UpdateHistory ¶
type UpdateHistory struct {
ID string `json:"id"`
FromVersion string `json:"from_version"`
ToVersion string `json:"to_version"`
Status string `json:"status"` // success, failed, rolled_back
AppliedAt time.Time `json:"applied_at"`
RolledBack bool `json:"rolled_back"`
}
UpdateHistory represents update history entry
type UpdateInfo ¶
type UpdateInfo struct {
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
UpdateAvailable bool `json:"update_available"`
ReleaseChannel string `json:"release_channel"`
ReleaseNotes string `json:"release_notes"`
DownloadURL string `json:"download_url"`
Checksum string `json:"checksum"`
Size int64 `json:"size"`
PublishedAt time.Time `json:"published_at"`
}
UpdateInfo represents available update information
type UpdateStatus ¶
type UpdateStatus struct {
State string `json:"state"` // idle, checking, downloading, applying, restarting, failed
Progress float64 `json:"progress"`
Error string `json:"error,omitempty"`
LastChecked time.Time `json:"last_checked"`
DownloadedPath string `json:"downloaded_path,omitempty"`
}
UpdateStatus represents current update status
type Version ¶
type Version struct {
Major int
Minor int
Patch int
Prerelease string // alpha, beta, rc
PreNum int // alpha1 -> 1, or bare revision like 0.4.2-1 -> 1
}
Version represents a semantic version
func ParseVersion ¶
ParseVersion parses a version string. Supports: 1.2.3, v1.2.3, 0.4.2-alpha1, 0.4.2-beta.1, 0.4.2-rc1, 0.4.2-1
func (*Version) Compare ¶
Compare compares two versions. Returns -1 if v < other, 0 if equal, 1 if v > other
func (*Version) IsNewerThan ¶
IsNewerThan returns true if v is newer than other