client

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig 配置无效错误
	ErrInvalidConfig = errors.New("invalid configuration")

	// ErrInvalidVersion 版本格式无效错误
	ErrInvalidVersion = errors.New("invalid version format")

	// ErrNetworkTimeout 网络超时错误
	ErrNetworkTimeout = errors.New("network timeout")

	// ErrDownloadFailed 下载失败错误
	ErrDownloadFailed = errors.New("download failed")

	// ErrVerificationFailed 文件校验失败错误
	ErrVerificationFailed = errors.New("file verification failed")

	// ErrExtractionFailed 解压失败错误
	ErrExtractionFailed = errors.New("extraction failed")

	// ErrUpdateFailed 更新失败错误
	ErrUpdateFailed = errors.New("update failed")

	// ErrBackupFailed 备份失败错误
	ErrBackupFailed = errors.New("backup failed")

	// ErrNoUpdateAvailable 无可用更新错误
	ErrNoUpdateAvailable = errors.New("no update available")
)

Functions

This section is empty.

Types

type Client

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

Client VersionTrack客户端

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient 创建新的客户端实例

func (*Client) CheckForMultipleUpdates added in v1.0.2

func (c *Client) CheckForMultipleUpdates(ctx context.Context, currentVersion string) (*UpdatesInfo, error)

CheckForMultipleUpdates 检查多版本更新(新版本)

func (*Client) CheckForUpdates

func (c *Client) CheckForUpdates(ctx context.Context, currentVersion string) (*UpdateInfo, error)

CheckForUpdates 检查是否有可用更新

func (*Client) Download

func (c *Client) Download(ctx context.Context, info *UpdateInfo, destPath string, callback ProgressCallback) error

Download 下载更新文件

func (*Client) DownloadVersion added in v1.0.2

func (c *Client) DownloadVersion(ctx context.Context, versionInfo *VersionInfo, destPath string, callback ProgressCallback) error

DownloadVersion 下载指定版本

func (*Client) GetRecommendedUpdate added in v1.0.2

func (c *Client) GetRecommendedUpdate(ctx context.Context, currentVersion string) (*VersionInfo, error)

GetRecommendedUpdate 获取推荐更新版本(自动模式)

func (*Client) GetUpdateHistory

func (c *Client) GetUpdateHistory() []UpdateRecord

GetUpdateHistory 获取更新历史

func (*Client) HasForcedUpdate added in v1.0.2

func (c *Client) HasForcedUpdate(ctx context.Context, currentVersion string) (*VersionInfo, error)

HasForcedUpdate 检查是否有强制更新

func (*Client) Rollback

func (c *Client) Rollback(ctx context.Context, version string) error

Rollback 回滚到指定版本

func (*Client) Update

func (c *Client) Update(ctx context.Context, info *UpdateInfo, downloadPath string) error

Update 执行更新

func (*Client) UpdateToVersion added in v1.0.2

func (c *Client) UpdateToVersion(ctx context.Context, targetVersion string, callback ProgressCallback) error

UpdateToVersion 手动选择版本更新

type ClientError

type ClientError struct {
	Code    string
	Message string
	Cause   error
}

ClientError 客户端错误类型

func NewClientError

func NewClientError(code, message string, cause error) *ClientError

NewClientError 创建客户端错误

func (*ClientError) Error

func (e *ClientError) Error() string

Error 实现error接口

func (*ClientError) Unwrap

func (e *ClientError) Unwrap() error

Unwrap 返回原始错误

type Config

type Config struct {
	// VersionTrack服务器地址
	ServerURL string
	// API密钥(必须)
	APIKey string
	// 平台信息 (windows/linux/macos)
	Platform string
	// 架构信息 (amd64/arm64)
	Arch string
	// HTTP请求超时时间
	Timeout time.Duration
	// 需要保护的文件列表(更新时不覆盖)
	PreserveFiles []string
	// 备份保留数量
	BackupCount int
	// 更新模式
	UpdateMode UpdateMode
	// 跳过的版本列表
	SkipVersions []string
}

Config 客户端配置

type DownloadProgress

type DownloadProgress struct {
	// 已下载字节数
	Downloaded int64
	// 总字节数
	Total int64
	// 下载速度 (bytes/second)
	Speed int64
	// 百分比
	Percentage float64
}

DownloadProgress 下载进度信息

type ProgressCallback

type ProgressCallback func(progress *DownloadProgress)

ProgressCallback 下载进度回调函数

type UpdateFile added in v1.0.1

type UpdateFile struct {
	ID                 string `json:"id"`
	VersionID          string `json:"versionId"`
	FileName           string `json:"fileName"`
	FilePath           string `json:"filePath"`
	FileSize           int64  `json:"fileSize"`
	FileHash           string `json:"fileHash"`
	Platform           string `json:"platform"`
	Arch               string `json:"arch"`
	FileType           string `json:"fileType"`
	DownloadURL        string `json:"downloadUrl"`
	IsCompressed       bool   `json:"isCompressed"`
	CompressionType    string `json:"compressionType"`
	Signature          string `json:"signature"`
	SignatureAlgorithm string `json:"signatureAlgorithm"`
	UploadStatus       string `json:"uploadStatus"`
}

UpdateFile 更新文件信息

type UpdateInfo

type UpdateInfo struct {
	// 是否有更新
	HasUpdate bool `json:"hasUpdate"`
	// 最新版本详情 - 修改为字符串类型
	LatestVersion string `json:"latestVersion"`
	// 当前版本
	CurrentVersion string `json:"currentVersion"`
	// 更新文件列表
	UpdateFiles []UpdateFile `json:"updateFiles"`
	// 是否强制更新
	IsForced bool `json:"isForced"`
	// 下载URL (从第一个匹配的文件获取)
	DownloadURL string `json:"-"`
	// 文件大小 (从第一个匹配的文件获取)
	FileSize int64 `json:"-"`
	// MD5哈希值 (从第一个匹配的文件获取)
	MD5Hash string `json:"-"`
	// 发布说明 (从版本详情获取)
	ReleaseNotes string `json:"-"`
	// 发布时间 (从版本详情获取)
	PublishedAt string `json:"-"`
	// 可用版本列表(新增)
	AvailableVersions []VersionInfo `json:"availableVersions"`
	// 更新策略(新增)
	UpdateStrategy UpdateStrategy `json:"updateStrategy"`
}

UpdateInfo 更新信息(旧版本,保持兼容)

type UpdateMode added in v1.0.2

type UpdateMode string

UpdateMode 更新模式

const (
	UpdateModeAuto   UpdateMode = "auto"   // 自动更新到最新版本
	UpdateModeManual UpdateMode = "manual" // 手动选择版本
	UpdateModePrompt UpdateMode = "prompt" // 提示用户选择
)

type UpdateRecord

type UpdateRecord struct {
	// 版本号
	Version string `json:"version"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt"`
	// 更新状态
	Status string `json:"status"`
	// 备份路径
	BackupPath string `json:"backupPath"`
}

UpdateRecord 更新记录

type UpdateStrategy added in v1.0.2

type UpdateStrategy struct {
	HasForced          bool   `json:"hasForced"`
	MinRequiredVersion string `json:"minRequiredVersion"`
}

UpdateStrategy 更新策略

type Updater

type Updater interface {
	// CheckForUpdates 检查是否有可用更新(旧版本,保持兼容)
	CheckForUpdates(ctx context.Context, currentVersion string) (*UpdateInfo, error)

	// CheckForMultipleUpdates 检查多版本更新(新版本)
	CheckForMultipleUpdates(ctx context.Context, currentVersion string) (*UpdatesInfo, error)

	// GetRecommendedUpdate 获取推荐更新版本(自动模式)
	GetRecommendedUpdate(ctx context.Context, currentVersion string) (*VersionInfo, error)

	// UpdateToVersion 手动选择版本更新
	UpdateToVersion(ctx context.Context, targetVersion string, callback ProgressCallback) error

	// HasForcedUpdate 检查是否有强制更新
	HasForcedUpdate(ctx context.Context, currentVersion string) (*VersionInfo, error)

	// Download 下载更新文件
	Download(ctx context.Context, info *UpdateInfo, destPath string, callback ProgressCallback) error

	// DownloadVersion 下载指定版本
	DownloadVersion(ctx context.Context, versionInfo *VersionInfo, destPath string, callback ProgressCallback) error

	// Update 执行更新
	Update(ctx context.Context, info *UpdateInfo, downloadPath string) error

	// GetUpdateHistory 获取更新历史
	GetUpdateHistory() []UpdateRecord

	// Rollback 回滚到指定版本
	Rollback(ctx context.Context, version string) error
}

Updater 更新器接口

type UpdatesInfo added in v1.0.2

type UpdatesInfo struct {
	// 是否有更新
	HasUpdate bool `json:"hasUpdate"`
	// 当前版本
	CurrentVersion string `json:"currentVersion"`
	// 最新版本
	LatestVersion string `json:"latestVersion"`
	// 可用版本列表
	AvailableVersions []VersionInfo `json:"availableVersions"`
	// 更新策略
	UpdateStrategy UpdateStrategy `json:"updateStrategy"`
}

UpdatesInfo 多版本更新信息(新版本)

type VersionDetail added in v1.0.1

type VersionDetail struct {
	ID                 string `json:"id"`
	ProjectID          string `json:"projectId"`
	Version            string `json:"version"`
	VersionWeight      int64  `json:"versionWeight"` // 版本权重,用于排序比较
	VersionName        string `json:"versionName"`
	Changelog          string `json:"changelog"`
	Status             string `json:"status"`             // 版本状态
	IsDownloadable     bool   `json:"isDownloadable"`     // 是否可下载
	DownloadableStatus string `json:"downloadableStatus"` // 下载状态描述
	ScheduledReleaseAt string `json:"scheduledReleaseAt"` // 预定发布时间(scheduled状态使用)
	CreatedBy          string `json:"createdBy"`
	PublishedAt        string `json:"publishedAt"`
}

VersionDetail 版本详细信息

type VersionInfo added in v1.0.2

type VersionInfo struct {
	Version            string `json:"version"`
	VersionWeight      int64  `json:"versionWeight"` // 版本权重,用于排序比较
	Changelog          string `json:"changelog"`
	ReleaseDate        string `json:"releaseDate"`
	DownloadURL        string `json:"downloadUrl"`
	FileSize           int64  `json:"fileSize"`
	FileHash           string `json:"fileHash"`
	Status             string `json:"status"`             // 版本状态 (draft, published, recalled, archived, scheduled)
	IsDownloadable     bool   `json:"isDownloadable"`     // 是否可下载
	DownloadableStatus string `json:"downloadableStatus"` // 下载状态描述
	ScheduledReleaseAt string `json:"scheduledReleaseAt"` // 预定发布时间(scheduled状态使用)
	IsForced           bool   `json:"isForced"`           // 是否强制更新
}

VersionInfo 版本信息

Jump to

Keyboard shortcuts

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