selfupdate

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Update protocol:

GET hk.heroku.com/hk/linux-amd64.json

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

then

GET hkpatch.s3.amazonaws.com/hk/1/2/linux-amd64

200 ok
[bsdiff data]

or

GET hkdist.s3.amazonaws.com/hk/2/linux-amd64.gz

200 ok
[gzipped executable data]

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

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).
	AppName        string    // Application name
	BinURL         string    // Base URL for full binary downloads.
	LocalStateDir  string    // Directory to store selfupdate state.
	ForceCheck     bool      // Check for update regardless of cktime timestamp
	Requester      Requester //Optional parameter to override existing http request handler
	CheckInterval  time.Duration
	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.

Example:

updater := &selfupdate.Updater{
	CurrentVersion: version,
	ApiURL:         "http://updates.yourdomain.com/",
	BinURL:         "http://updates.yourdownmain.com/",
	DiffURL:        "http://updates.yourdomain.com/",
	DirName:            "update/",
	AppName:        "myapp", // app name
}
if updater != nil {
	go updater.Update()
}

func (*Updater) CheckVersion added in v0.0.5

func (u *Updater) CheckVersion() (*semver.Version, error)

CheckVersion checks if there is an update without pulling the binary

func (*Updater) NextUpdate added in v0.0.5

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

NextUpdate returns the next time update should be checked

func (*Updater) SetUpdateTime added in v0.0.5

func (u *Updater) SetUpdateTime()

SetUpdateTime writes the next update time to the state file

func (*Updater) Update added in v0.0.5

func (u *Updater) Update() (bool, error)

Update starts the update returns true if it gets updated

Jump to

Keyboard shortcuts

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