updates.go 1.04 KB
Newer Older
1 2 3 4 5
package updates

import (
	"os"

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
6
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
7 8
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update"
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update/check"
9
	u "github.com/jbenet/go-ipfs/util"
10 11 12
)

const (
13 14 15
	Version           = "0.1.0" // actual current application's version literal
	UpdateEndpointURL = "https://api.equinox.io/1/Updates"
	UpdateAppID       = "ap_ywkPmAR40q4EfdikN9Jh2hgIHi"
16 17
)

18 19
var log = u.Logger("updates")

20 21 22 23
var currentVersion *semver.Version

func init() {
	var err error
24
	currentVersion, err = parseVersion()
25
	if err != nil {
26
		log.Error("illegal version number in code: %q\n", Version)
27 28 29 30
		os.Exit(1)
	}
}

31 32 33
func parseVersion() (*semver.Version, error) {
	return semver.NewVersion(Version)
}
34 35 36 37 38 39

func CheckForUpdate() (*check.Result, error) {
	param := check.Params{
		AppVersion: Version,
		AppId:      UpdateAppID,
		Channel:    "stable",
40
	}
41 42

	return param.CheckForUpdate(UpdateEndpointURL, update.New())
43
}