Documentation
¶
Overview ¶
Package update provides functionality for self-updating the application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater handles the self-update process.
It manages checking for updates on GitHub and applying them to the local executable.
Summary: Represents a Updater.
func NewUpdater ¶
NewUpdater creates a new Updater.
Parameters:
- httpClient: *http.Client. The HTTP client to use for network requests. If nil, http.DefaultClient is used.
- githubAPIURL: string. Optional URL for the GitHub API (useful for Enterprise GitHub).
Returns:
- *Updater: A new Updater instance.
Summary: Initializes NewUpdater operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Updater) CheckForUpdate ¶
func (u *Updater) CheckForUpdate(ctx context.Context, owner, repo, currentVersion string) (*github.RepositoryRelease, bool, error)
CheckForUpdate checks for a new release on GitHub.
It compares the provided current version tag with the latest release tag on the repository.
Parameters:
- ctx: context.Context. The context for the request.
- owner: string. The GitHub repository owner (e.g., "mcpany").
- repo: string. The GitHub repository name (e.g., "core").
- currentVersion: string. The current version tag of the application.
Returns:
- *github.RepositoryRelease: The release information if an update is available, nil otherwise.
- bool: True if a newer version is available, false otherwise.
- error: An error if the check fails (e.g., network error, API rate limit).
Summary: Executes CheckForUpdate operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Updater) UpdateTo ¶
func (u *Updater) UpdateTo(ctx context.Context, fs afero.Fs, executablePath string, release *github.RepositoryRelease, assetName, checksumsAssetName string) error
UpdateTo downloads the new release, verifies its checksum, and replaces the current executable.
It handles downloading artifacts, verifying SHA256 checksums, and safely swapping the binary.
Parameters:
- ctx: context.Context. The context for the request.
- fs: afero.Fs. The file system abstraction (usually afero.NewOsFs()).
- executablePath: string. The path to the currently running executable to replace.
- release: *github.RepositoryRelease. The release object to update to.
- assetName: string. The name of the binary asset to download.
- checksumsAssetName: string. The name of the checksums file asset.
Returns:
- error: An error if any step of the update process fails (download, verify, replace).
Side Effects:
- Writes temporary files to disk.
- Modifies the executable file on disk.
Summary: Executes UpdateTo operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.