Documentation
¶
Overview ¶
Package update keeps a Lightron app up to date from a feed: a JSON file listing the latest version and a package per platform (what `lightron feed` writes), e.g. the update.json of a GitHub release:
{"version": "1.2.0", "notes": "…", "packages": {
"darwin-arm64": {"file": "Notes-1.2.0-darwin-arm64.dmg", "size": 18900000, "sha256": "…"},
"windows-amd64": {"file": "Notes-1.2.0-windows-amd64-setup.exe", "size": 13900000, "sha256": "…"}}}
Check downloads the newer package (checked: size, sha256; tried again when the server fails); Install puts it in place once the app has quit: macOS swaps the .app and opens the new one, Windows runs the installer silently.
u := update.New(update.Options{FeedURL: "https://github.com/me/notes/releases/latest/download/update.json",
Current: version, Dir: dataDir})
if rel, err := u.Check(ctx); err == nil && rel != nil {
if ask(rel.Version) && rel.Install() == nil {
app.Quit()
}
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotUpdatable = errors.New("update: this build's version can't be compared with releases")
ErrNotUpdatable: Current isn't a version Check can compare (0.1.0-dev, empty). Such builds don't update.
Functions ¶
func ParseVersion ¶
ParseVersion reads a release (x.y.z, v optional) or a git describe (x.y.z-N-gabc[-dirty]) as [x, y, z, N], N being commits past the x.y.z tag: a local build is ahead of the release it was built on and behind the next one. nil for anything else (0.1.0-dev).
Types ¶
type Feed ¶
type Feed struct {
Version string `json:"version"`
Notes string `json:"notes,omitempty"`
Packages map[string]Package `json:"packages"`
}
Feed is what a feed says.
type Options ¶
type Options struct {
// FeedURL is the feed's address. The packages are found next to it (same directory), so
// …/releases/latest/download/update.json on GitHub works as is.
FeedURL string
// Current is this build's version: x.y.z, or a git describe (x.y.z-N-gabc, -dirty).
Current string
// Dir is where downloads wait until installed. Default: a directory under os.TempDir().
Dir string
// Platform is the feed's key for this build. Default: GOOS-GOARCH (darwin-arm64, windows-amd64).
Platform string
// Client makes the requests. Default: http.DefaultClient.
Client *http.Client
// Logf receives retries and the like. Default: log.Printf.
Logf func(format string, args ...any)
}
Options configure an Updater.
type Package ¶
type Package struct {
File string `json:"file"`
Size int64 `json:"size"`
Sha256 string `json:"sha256"`
}
Package is one platform's file in a feed.