utils

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const GitHubAPIURL = "https://api.github.com/repos/NiloCK/tuido/releases/latest"
View Source
const ReleaseURL = "https://github.com/NiloCK/tuido/releases/latest"

Variables

This section is empty.

Functions

func BuildAssetName added in v0.0.16

func BuildAssetName(version, goos, goarch string) string

BuildAssetName constructs the expected asset name for a given platform

func CleanupBackups added in v0.0.16

func CleanupBackups(executablePath string, keepCount int) error

CleanupBackups removes old backup files

func CopyFile added in v0.0.16

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst

func DownloadAsset added in v0.0.16

func DownloadAsset(asset *ReleaseAsset, filePath string, config *DownloadConfig) error

DownloadAsset downloads an asset to the specified file path with progress tracking

func ExtractExecutableFromArchive added in v0.0.16

func ExtractExecutableFromArchive(archivePath, extractDir string) (string, error)

ExtractExecutableFromArchive extracts the executable from a tar.gz archive

func GetBusyExecutableInfo added in v0.0.16

func GetBusyExecutableInfo(err error) (currentPath, newPath string, ok bool)

GetBusyExecutableInfo returns information about a busy executable error

func GetTerminalColorSupport

func GetTerminalColorSupport() string

returns a string used for chroma syntax highlighting

func IsBusyExecutableError added in v0.0.16

func IsBusyExecutableError(err error) bool

IsBusyExecutableError checks if an error is a BusyExecutableError

func LatestVersion added in v0.0.9

func LatestVersion() string

func ReplaceExecutable added in v0.0.16

func ReplaceExecutable(currentPath, newPath string, config *UpgradeConfig) error

ReplaceExecutable handles the platform-specific logic of replacing the executable

func RestoreFromBackup added in v0.0.16

func RestoreFromBackup(executablePath, backupPath string) error

RestoreFromBackup restores the executable from a backup file

func ValidateAssetIntegrity added in v0.0.16

func ValidateAssetIntegrity(filePath string, expectedSize int64) error

ValidateAssetIntegrity verifies the downloaded asset (placeholder for future checksum validation)

func Version added in v0.0.9

func Version() string

Version returns the currently running version of the application.

Types

type BusyExecutableError added in v0.0.16

type BusyExecutableError struct {
	CurrentPath string
	NewPath     string
	Message     string
}

BusyExecutableError indicates that the executable couldn't be replaced because it's busy

func (*BusyExecutableError) Error added in v0.0.16

func (e *BusyExecutableError) Error() string

type DownloadConfig added in v0.0.16

type DownloadConfig struct {
	// Context for cancellation
	Context context.Context
	// Progress callback (optional)
	OnProgress ProgressCallback
	// Retry count for failed downloads
	RetryCount int
	// Timeout for each download attempt
	Timeout time.Duration
}

DownloadConfig contains configuration for downloading assets

func DefaultDownloadConfig added in v0.0.16

func DefaultDownloadConfig() *DownloadConfig

DefaultDownloadConfig returns a reasonable default configuration

type GitHubRelease added in v0.0.16

type GitHubRelease struct {
	TagName string         `json:"tag_name"`
	Assets  []ReleaseAsset `json:"assets"`
}

GitHubRelease represents a GitHub release

func FetchLatestReleaseFromURL added in v0.0.16

func FetchLatestReleaseFromURL(apiURL string) (*GitHubRelease, error)

FetchLatestReleaseFromURL retrieves release information from a specific URL (testable version)

type ProgressCallback added in v0.0.16

type ProgressCallback func(downloaded, total int64)

ProgressCallback is called during download to report progress

type ReleaseAsset added in v0.0.16

type ReleaseAsset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
	Size        int64  `json:"size"`
}

ReleaseAsset represents a GitHub release asset

func GetCurrentPlatformAsset added in v0.0.16

func GetCurrentPlatformAsset() (*ReleaseAsset, error)

GetCurrentPlatformAsset returns the appropriate asset for the current platform

type UpgradeConfig added in v0.0.16

type UpgradeConfig struct {
	// Context for cancellation
	Context context.Context
	// Download configuration
	DownloadConfig *DownloadConfig
	// Whether to create a backup before replacement
	CreateBackup bool
	// Backup file suffix
	BackupSuffix string
	// Whether to attempt restart after upgrade
	AttemptRestart bool
}

UpgradeConfig contains configuration for the upgrade process

func DefaultUpgradeConfig added in v0.0.16

func DefaultUpgradeConfig() *UpgradeConfig

DefaultUpgradeConfig returns a reasonable default configuration

type UpgradeResult added in v0.0.16

type UpgradeResult struct {
	// Whether the upgrade was successful
	Success bool
	// Path to the new executable
	NewExecutablePath string
	// Path to the backup file (if created)
	BackupPath string
	// Whether a restart is required
	RestartRequired bool
	// Any error that occurred
	Error error
}

UpgradeResult contains information about the upgrade process

func PerformUpgrade added in v0.0.16

func PerformUpgrade(config *UpgradeConfig) *UpgradeResult

PerformUpgrade downloads and replaces the current executable with a new version

Jump to

Keyboard shortcuts

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