Documentation
¶
Index ¶
- Constants
- func CanSelfUpgrade() (bool, string)
- func CheckWritePermission(targetPath string) error
- func CompareVersions(current, target *semver.Version) int
- func Download(ctx context.Context, opts DownloadOptions) error
- func ExtractVersionFromTag(tag string) string
- func FormatBytes(bytes int64) string
- func FormatCheckResult(r *Result) string
- func FormatResult(r *Result) string
- func GetExecutablePath() (string, error)
- func IsCacheValid(cache *UpgradeCheckCache) bool
- func IsNewer(current, target *semver.Version) bool
- func NormalizeVersionTag(version string) string
- func ParseVersion(s string) (*semver.Version, error)
- func SupportedPlatformsMessage() string
- func ValidateVersionTag(tag string) error
- func VerifyBinary(binaryPath, expectedVersion string) error
- func VerifyChecksum(filePath, expectedHash string) error
- type Asset
- type CacheStore
- type DownloadOptions
- type GitHubClient
- type InstallMethod
- type InstallOptions
- type InstallResult
- type Options
- type Platform
- type Release
- type ReleaseInfo
- type Result
- type UpgradeCheckCache
Constants ¶
const ( // CacheTTL is how long the cache is valid. CacheTTL = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func CanSelfUpgrade ¶
CanSelfUpgrade returns true if dagu can perform a self-upgrade.
func CheckWritePermission ¶
CheckWritePermission verifies we can write to the target directory.
func CompareVersions ¶
CompareVersions compares two versions. Returns: -1 if current < target, 0 if equal, 1 if current > target
func Download ¶
func Download(ctx context.Context, opts DownloadOptions) error
Download downloads a file with checksum verification. The entire GET + stream-to-file + checksum-verify is wrapped in a retry loop so that mid-stream failures (io.Copy errors) are also retried.
func ExtractVersionFromTag ¶
ExtractVersionFromTag extracts the version number from a tag like "v1.30.3".
func FormatBytes ¶
FormatBytes formats byte count in human-readable format.
func FormatCheckResult ¶
FormatCheckResult formats the check result for display.
func FormatResult ¶
FormatResult formats the upgrade result for display.
func GetExecutablePath ¶
GetExecutablePath returns the path to the currently running binary.
func IsCacheValid ¶
func IsCacheValid(cache *UpgradeCheckCache) bool
IsCacheValid checks if the cache is still valid (not expired).
func NormalizeVersionTag ¶
NormalizeVersionTag ensures a version string has a 'v' prefix.
func ParseVersion ¶
ParseVersion parses a version string into a semver.Version.
func SupportedPlatformsMessage ¶
func SupportedPlatformsMessage() string
SupportedPlatformsMessage returns a message listing all supported platforms.
func ValidateVersionTag ¶
ValidateVersionTag rejects tags that contain path-traversal sequences, directory separators, or control characters.
func VerifyBinary ¶
VerifyBinary runs the installed binary with "version" argument to verify it works.
func VerifyChecksum ¶
VerifyChecksum computes SHA256 and compares with expected hash.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
Size int64 `json:"size"`
ContentType string `json:"content_type"`
}
Asset represents a GitHub release asset.
type CacheStore ¶
type CacheStore interface {
Load() (*UpgradeCheckCache, error)
Save(cache *UpgradeCheckCache) error
}
CacheStore provides persistence for upgrade check cache data.
type DownloadOptions ¶
type DownloadOptions struct {
URL string
Destination string // Temp file path
ExpectedHash string // SHA256 from checksums.txt
OnProgress func(downloaded, total int64)
}
DownloadOptions configures the download operation.
type GitHubClient ¶
type GitHubClient struct {
// contains filtered or unexported fields
}
GitHubClient is an HTTP client for the GitHub Releases API.
func NewGitHubClient ¶
func NewGitHubClient() *GitHubClient
NewGitHubClient creates a new GitHub API client.
func (*GitHubClient) GetChecksums ¶
func (c *GitHubClient) GetChecksums(ctx context.Context, release *Release) (map[string]string, error)
GetChecksums downloads and parses checksums.txt from a release. Returns a map of filename to SHA256 hash.
func (*GitHubClient) GetLatestRelease ¶
func (c *GitHubClient) GetLatestRelease(ctx context.Context, includePreRelease bool) (*Release, error)
GetLatestRelease fetches the latest release from GitHub. If includePreRelease is true, it may return a pre-release version.
func (*GitHubClient) GetRelease ¶
GetRelease fetches a specific release by tag.
type InstallMethod ¶
type InstallMethod int
InstallMethod represents how dagu was installed.
const ( InstallMethodUnknown InstallMethod = iota InstallMethodBinary InstallMethodHomebrew InstallMethodSnap InstallMethodDocker InstallMethodGoInstall )
func DetectInstallMethod ¶
func DetectInstallMethod() InstallMethod
DetectInstallMethod checks how dagu was installed.
func (InstallMethod) String ¶
func (m InstallMethod) String() string
String returns a human-readable name for the install method.
type InstallOptions ¶
type InstallOptions struct {
ArchivePath string // Downloaded .tar.gz
TargetPath string // Path to current dagu binary
CreateBackup bool
ExpectedVersion string // for verification after install
}
InstallOptions configures the installation operation.
type InstallResult ¶
InstallResult contains information about the installation.
func Install ¶
func Install(ctx context.Context, opts InstallOptions) (*InstallResult, error)
Install extracts the binary from the archive and replaces the current binary.
type Options ¶
type Options struct {
TargetVersion string // Empty = latest
CheckOnly bool
DryRun bool
CreateBackup bool
Force bool
IncludePreRelease bool
OnProgress func(downloaded, total int64)
}
Options configures the upgrade operation.
type Platform ¶
type Platform struct {
OS string // runtime.GOOS: linux, darwin, freebsd, openbsd, windows
Arch string // Mapped from runtime.GOARCH to release asset naming
}
Platform represents the current operating system and architecture.
func (Platform) AssetName ¶
AssetName returns the expected filename for this platform and version. Format: dagu_<version_without_v>_<os>_<arch>.tar.gz
func (Platform) IsSupported ¶
IsSupported checks if the current platform is supported for self-upgrade.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
Name string `json:"name"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
HTMLURL string `json:"html_url"`
Assets []Asset `json:"assets"`
}
Release represents a GitHub release.
type ReleaseInfo ¶
type ReleaseInfo struct {
Release *Release
Checksums map[string]string
Asset *Asset
TargetVersion *semver.Version
}
ReleaseInfo contains pre-fetched release data to avoid multiple API calls.
func FetchReleaseInfo ¶
func FetchReleaseInfo(ctx context.Context, opts Options) (*ReleaseInfo, error)
FetchReleaseInfo fetches all release information in a single set of API calls. This allows checking and upgrading without making duplicate requests. Note: Callers are expected to check CanSelfUpgrade() before calling this.
type Result ¶
type Result struct {
CurrentVersion string
TargetVersion string
UpgradeNeeded bool
WasUpgraded bool
BackupPath string
DryRun bool
AssetName string
AssetSize int64
DownloadURL string
ExecutablePath string
SpecificVersionRequest bool
}
Result contains the result of an upgrade operation.
func UpgradeWithReleaseInfo ¶
func UpgradeWithReleaseInfo(ctx context.Context, opts Options, info *ReleaseInfo, store CacheStore) (*Result, error)
UpgradeWithReleaseInfo performs the upgrade using pre-fetched release information.
type UpgradeCheckCache ¶
type UpgradeCheckCache struct {
LastCheck time.Time `json:"lastCheck"`
LatestVersion string `json:"latestVersion"`
CurrentVersion string `json:"currentVersion"`
UpdateAvailable bool `json:"updateAvailable"`
}
UpgradeCheckCache stores the result of an upgrade check.
func CheckAndUpdateCache ¶
func CheckAndUpdateCache(ctx context.Context, store CacheStore, currentVersion string) (*UpgradeCheckCache, error)
CheckAndUpdateCache checks for updates if cache is stale and updates the cache. This function is designed to be called asynchronously.
func GetCachedUpdateInfo ¶
func GetCachedUpdateInfo(store CacheStore) *UpgradeCheckCache
GetCachedUpdateInfo returns cached update information if available. Returns nil if no valid cache exists.