Documentation ¶
Overview ¶
Package selfupdater implements logic behind self-updating App. It uses github releases to update your app.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Updater ¶
type Updater struct { Owner string Repo string Current semver.Version // contains filtered or unexported fields }
Updater is the main structure in charge to check latest version and update your app.
func New ¶
func New(owner, repo string, current semver.Version, options ...UpdaterOpts) *Updater
New creates a new instance of Updater. It needs the owner and repo name to work and the current version of your app (in semver format -> [semver package]) You can pass some options (WithContext, WithHttpClient) so that the updater can fits your need. If you don't, the Updater will use context.Background and http.DefaultClient by default. [semver package]: https://github.com/blang/semver
func (*Updater) CheckAndUpdate ¶
CheckAndUpdate will perform both the Updater.CheckLatest and Updater.Update actions. It may seems a better solution for the developper as you don't have to do some plumbering but it enforce the user to update the application.
func (*Updater) CheckLatest ¶
CheckLatest will check if the current version is the latest. It returns a boolean and an error. To avoid wrong behaviour, it returns true if an error is encountered.
func (*Updater) Update ¶
Update will perfom the update process which means : 1. Retrieve the corresponding asset (based on platform - os/arch - it needs to appear in the name like `my-super-app_linux-amd64`). 2. Download latest release asset for the current platform (os/arch). 3. Rename the current process executable with a `-old` suffix. 4. Give execution permission to the new executable. 5. Try to launch the new executable. 6. Try to rollack if it fails by removing the download executable and remove the `-old` suffix.
type UpdaterOpts ¶
type UpdaterOpts func(*Updater)
UpdaterOpts represent an option you can pass to Updater constructor. It uses functional option pattern so the underlying type is `func(*Updater)`.
func WithContext ¶
func WithContext(ctx context.Context) UpdaterOpts
WithContext will pass the given context to an Updater instance.
func WithHttpClient ¶
func WithHttpClient(client *http.Client) UpdaterOpts
WithHttpClient will pass the given *http.Client to an Updater instance.