go-selfupdate

module
v0.0.0-...-5689243 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2019 License: MIT

README

go-selfupdate

GoDoc Build Status

Enable your Golang applications to self update. Inspired by Chrome based on Heroku's hk.

Requires Golang 1.8 or higher.

Features

  • Tested on Mac, Linux, Arm, and Windows
  • Creates binary diffs with bsdiff allowing small incremental updates (which means you need to get bzip2 installed on your machine for this package to work)
  • Falls back to full binary update if diff fails to match SHA

QuickStart

Install library and update/patch creation utility

go get -u github.com/EliCDavis/go-selfupdate/...

Enable your App to Self Update
updater := selfupdate.NewUpdater(version, "http://updates.yourdomain.com/", "myapp")

// run an update in the background
go func () {
    updated, err := updater.Run()
    if err != nil {
        log.Printf("Error updating: %s", err.Error())
    } else {
        log.Printf("Update applied: %t", updated)
    }
}

If you prefer to instead of keeping this app updated, but a different file, just specify the path:

updater := selfupdate.NewUpdater(version, "http://updates.yourdomain.com/", "myapp").
    SetUpdatableResolver(NewSpecificFileUpdatableResolver("path/to/your/file"))

// run an update in the background
go func () {
    updated, err := updater.Run()
    if err != nil {
        log.Printf("Error updating: %s", err.Error())
    } else {
        log.Printf("Update applied: %t", updated)
    }
}
Push Out and Update
go-selfupdate myapp 1.2

This will create a folder in your project called, public you can then rsync or transfer this to your webserver or S3.

If you are cross compiling you can specify a directory:

go-selfupdate /tmp/mybinares/ 1.2

The directory should contain files with the name, $GOOS-$ARCH. Example:

windows-386
darwin-amd64
linux-arm

If you are using goxc you can output the files with this naming format by specifying this config:

"OutPath": "{{.Dest}}{{.PS}}{{.Version}}{{.PS}}{{.Os}}-{{.Arch}}",

Development

Uses mockgen to generate mocks for our interfaces. If you make any changes to any of the interface signatures, you'll need to update the mocks using the command:

go generate ./...

Directories

Path Synopsis
cmd
example
Package selfupdate 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]
Package selfupdate 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]
mocks
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