autoupdate

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 22 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package autoupdate installs newer stable GitHub releases over HTTPS and owns no host APIs.

Index

Constants

View Source
const DefaultSchedule = "50 4 * * *"

DefaultSchedule checks for updates daily at 04:50 local time.

Variables

This section is empty.

Functions

func IsNewer

func IsNewer(latest, current string) bool

IsNewer reports whether both identities are stable and latest is strictly newer.

func IsStable

func IsStable(version string) bool

IsStable reports whether version identifies a complete stable release. Development builds, pseudo-versions, prereleases and build metadata are excluded.

func Version

func Version() string

Version returns the running application's Go module version verbatim. Go preserves dirty, pseudo-version and development identities in build metadata.

Types

type Config

type Config struct {
	Repository     string                      // GitHub owner/repository.
	CurrentVersion string                      // Actual running build identity, including development/dirty markers.
	Binary         string                      // Root archive member, including .exe on Windows.
	ArchiveName    func(version string) string // Exact asset basename; version has no leading v.
	Client         *http.Client                // GitHub API only; never used for public archive downloads.
	Log            *slog.Logger                // Required.
	TaskName       string                      // Windows launch context: task must use MultipleInstances Queue; empty means foreground.
}

Config identifies one application's release and current executable.

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule is an immutable parsed five-field maintenance schedule. Day-of-month and day-of-week constraints both apply.

func ParseSchedule

func ParseSchedule(expr string) (Schedule, error)

ParseSchedule parses minute, hour, day-of-month, month and weekday fields. Fields support '*', integers, comma-separated lists, '*/N' and 'start/N'.

func (Schedule) Next

func (s Schedule) Next(now time.Time) time.Time

Next returns the next matching local minute strictly after now. It returns zero if no minute matches within a complete 400-year Gregorian calendar cycle.

type Updater

type Updater struct {
	// contains filtered or unexported fields
}

Updater serializes manual and scheduled installation for one running application. Hosts must share one instance and drain their resources before calling Restart.

func New

func New(cfg Config) (*Updater, error)

New prepares an updater for the actual running executable. The application must own the executable directory. Call it even when scheduling is disabled: Windows startup removes the previous image left by a committed update. Development identities may discover releases but never replace the binary. Client authentication stays on api.github.com.

func (*Updater) Latest

func (u *Updater) Latest(ctx context.Context) (string, error)

Latest returns the latest stable release identity, including for development builds.

func (*Updater) Restart

func (u *Updater) Restart() error

Restart relaunches the executable with its original arguments and environment after the application has drained its workers, listeners and watchers. Unix replaces the process. On Windows, TaskName queues that task (which must use MultipleInstances Queue); otherwise it starts a foreground replacement child. The Windows caller must exit after Restart returns successfully.

func (*Updater) Run

func (u *Updater) Run(ctx context.Context, sched Schedule) (string, error)

Run waits for local schedule occurrences until cancellation or a committed update. Each check adds an independent random delay from zero through five minutes. Failed checks are logged and retried on the next occurrence. The host owns graceful shutdown and must call Restart only after workers, listeners and watchers close.

func (*Updater) Update

func (u *Updater) Update(ctx context.Context) (version string, err error)

Update installs a strictly newer stable release and returns its version after commit, or an empty string when no installation is needed. Cancellation before commit leaves the executable unchanged; cancellation after commit does not undo it. Use an application-owned context, not a short-lived HTTP request context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL