selfupdate

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2021 License: MIT Imports: 22 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 ErrSignatureMismatch = errors.New("new file signature mismatch after patch")

Functions

func CreateUpdate

func CreateUpdate(version Info, path string, platform string, genDir string, pk *rsa.PrivateKey)

func GenerateSha256

func GenerateSha256(path string) []byte

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 Info

type Info struct {
	Version   string
	Sha256    []byte
	Signature []byte
}

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
	PublicKey      *rsa.PublicKey // Optional parameter to check signature in the update. If a key is set any binary must be checked with supplied Signature hash of API
	Target         string         // Optional parameter to specify binary to update. Set to current executable if not specified
	Platform       string         // Optional parameter to specify platform. Defaults to ${runtime.GOOS}-${runtime.GOARCH}
}

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/",
	Dir:            "update/",
	CmdName:        "myapp", // app name
}
if updater != nil {
	go updater.BackgroundRun()
}

func (*Updater) BackgroundRun

func (u *Updater) BackgroundRun() (Info, error)

BackgroundRun starts the update check and apply cycle. A new applied version is returned.

func (*Updater) ClearUpdateState

func (u *Updater) ClearUpdateState()

ClearUpdateState writes current time to state file

func (*Updater) GetNextVersion

func (u *Updater) GetNextVersion() (Info, error)

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() (Info, 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

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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