modulepackage
1.1.0
Repository: https://github.com/sierrasoftworks/update-go.git
Documentation: pkg.go.dev
# README
update-go
An automated update library for Go applications
This library provides the functionality necessary to implement automated updates for your applications.
Example
package main
import (
"os"
"log"
"path/filepath"
"github.com/SierraSoftworks/update-go"
)
// Update this on each new release (ideally using the "-X main.version=1.1.7" compiler flag)
var version = "1.0.0"
func main() {
mgr := update.Manager{
Application: os.Args[0],
UpgradeApplication: filepath.Join(os.TempDir(), filepath.Base(os.Args[0])),
Variant: update.MyPlatform(),
Source: update.NewGitHubSource("SierraSoftworks/git-tool", "v", "git-tool-"),
}
// Resume an ongoing update operation (this may terminate the application as
// part of the upgrade process).
err := mgr.Continue()
if err != nil {
log.Fatalf("Unable to apply updates: %s", err)
}
// Your application code
log.Println("Foo Bar!")
rs, err := mgr.Source.Releases()
if err != nil {
log.Fatalf("Unable to fetch the list of available updates", err)
}
availableUpdate := update.LatestUpdate(rs, version)
if availableUpdate != nil {
log.Infof("Update available: %s", availableUpdate.ID)
log.Infof("Changes: %s", availableUpdate.Changelog)
err := mgr.Update(availableUpdate)
if err != nil {
log.Fatalf("Unable to start update: %s", err)
}
} else {
log.Infof("No updates available")
}
}
# Functions
Latest returns the latest from a collection of releases.
LatestUpdate gets the latest release which is also an update over the currently running application version.
MyPlatform returns the variant representing your current platform.
NewGitHubSource creates a new update source which consumes releases from GitHub.
# Constants
PhaseCleanup involves the primary application (following an upgrade) being tasked with the removal of the temporary update binary.
PhasePrepare represents the initial preparation phase, in which the latest release is downloaded to a temporary directory before being launched to enter the replacement phase.
PhaseReplace involves the latest release being launched in its temporary directory with the task of replacing the primary application binary once all instances of the primary application have terminated.
# Structs
The Applier is responsible for applying each stage of the update operation.
The Manager is responsible for coordinating an application's upgrade as it moves between each of the upgrade phases.
A Release describes a specific release of the software.
A Variant describes a platform specific build of the software.
# Interfaces
A Source provides both information on the availability of versions as well as the ability to download a specific version on request.
# Type aliases
Phase describes which phase the update state machine is currently in.