Version: v0.0.0-...-c9b625f Latest Latest

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 19 Imported by: 20



Update protocol:


200 ok
    "Version": "2",
    "Sha256": "..." // base64



200 ok
[bsdiff data]



200 ok
[gzipped executable data]



This section is empty.


View Source
var ErrHashMismatch = errors.New("new file hash mismatch after patch")


This section is empty.


type HTTPRequester

type HTTPRequester struct {

HTTPRequester is the normal requester that is used and does an HTTP to the url location requested to retrieve the specified data.

func (*HTTPRequester) Fetch

func (httpRequester *HTTPRequester) Fetch(url string) (io.ReadCloser, error)

Fetch will return an HTTP request to the specified url and return the body of the result. An error will occur for a non 200 status code.

type Requester

type Requester interface {
	Fetch(url string) (io.ReadCloser, error)

Requester interface allows developers to customize the method in which requests are made to retrieve the version and binary

type Updater

type Updater struct {
	CurrentVersion string    // Currently running version.
	ApiURL         string    // Base URL for API requests (json files).
	CmdName        string    // Command name is appended to the ApiURL like http://apiurl/CmdName/. This represents one binary.
	BinURL         string    // Base URL for full binary downloads.
	DiffURL        string    // Base URL for diff downloads.
	Dir            string    // Directory to store selfupdate state.
	ForceCheck     bool      // Check for update regardless of cktime timestamp
	CheckTime      int       // Time in hours before next check
	RandomizeTime  int       // Time in hours to randomize with CheckTime
	Requester      Requester //Optional parameter to override existing http request handler
	Info           struct {
		Version string
		Sha256  []byte

Updater is the configuration and runtime data for doing an update.

Note that ApiURL, BinURL and DiffURL should have the same value if all files are available at the same location.


updater := &selfupdate.Updater{
	CurrentVersion: version,
	ApiURL:         "",
	BinURL:         "",
	DiffURL:        "",
	Dir:            "update/",
	CmdName:        "myapp", // app name
if updater != nil {
	go updater.BackgroundRun()

func (*Updater) BackgroundRun

func (u *Updater) BackgroundRun() error

BackgroundRun starts the update check and apply cycle.

func (*Updater) ClearUpdateState

func (u *Updater) ClearUpdateState()

ClearUpdateState writes current time to state file

func (*Updater) NextUpdate

func (u *Updater) NextUpdate() time.Time

NextUpdate returns the next time update should be checked

func (*Updater) SetUpdateTime

func (u *Updater) SetUpdateTime() bool

SetUpdateTime writes the next update time to the state file

func (*Updater) Update

func (u *Updater) Update() error

Update initiates the self update process

func (*Updater) UpdateAvailable

func (u *Updater) UpdateAvailable() (string, error)

UpdateAvailable checks if update is available and returns version

func (*Updater) WantUpdate

func (u *Updater) WantUpdate() bool

WantUpdate returns boolean designating if an update is desired

Jump to

Keyboard shortcuts

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