Overview
Thereleaser package provides utilities for checking GitHub releases and comparing versions. It’s designed for CLI tools that need to notify users about available updates.
Import path:
Types
Info
The version tag of the release (e.g.,
"v1.2.3")The URL to download the release tarball
Functions
FetchInfo
The GitHub API URL to fetch release information from.Example:
"https://api.github.com/repos/raystack/salt/releases/latest"Release information containing version and tarball URL
Error if the HTTP request fails, returns non-200 status, or JSON parsing fails
- Sets timeout to
releaser.Timeout(default 1 second) - Sets User-Agent header to
"raystack/salt" - Parses JSON fields:
tag_nameandtarball_url - Returns error on non-200 HTTP status codes
CompareVersions
The current version string (e.g.,
"v1.0.0")The latest version string to compare against (e.g.,
"v1.2.0")true if current version is greater than or equal to latest version, false otherwiseError if version string parsing fails (invalid semantic version format)
- Uses
github.com/hashicorp/go-versionfor semantic version parsing - Supports standard semantic versioning (MAJOR.MINOR.PATCH)
- Handles version prefixes (e.g.,
"v"in"v1.0.0")
CheckForUpdate
The current version of your application (e.g.,
"v1.0.0")GitHub repository in the format
"owner/repo" (e.g., "raystack/salt")Update message if a newer version is available. Returns empty string if:
- Current version is up-to-date
- Error occurs during fetch or comparison
- Network request fails
- Constructs GitHub API URL using
APIFormattemplate - Calls
FetchInfo()to get latest release - Calls
CompareVersions()to check if update is needed - Silently handles errors by returning empty string
- Does not block or panic on failure
Variables
Timeout
APIFormat
%s is replaced with the repository name in "owner/repo" format.
Example:
Error Handling
The package can return errors in these scenarios:| Error Type | Cause | Returned By |
|---|---|---|
| HTTP request creation failed | Invalid URL | FetchInfo() |
| Network error | Connection timeout, DNS failure | FetchInfo() |
| Non-200 status code | Repository not found, rate limit | FetchInfo() |
| JSON parsing error | Invalid API response format | FetchInfo() |
| Version parsing error | Invalid semantic version string | CompareVersions() |
Complete Example
Source Code Reference
- Package location:
/home/daytona/workspace/source/cli/releaser/release.go - Uses
github.com/hashicorp/go-versionfor version comparison - Uses
github.com/pkg/errorsfor error wrapping