-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.go
52 lines (44 loc) · 1.22 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"github.com/equinox-io/equinox"
)
// assigned when creating a new application in the dashboard
const appID = "app_89L1xne6sL5"
// public portion of signing key generated by `equinox genkey`
var publicKey = []byte(`
-----BEGIN ECDSA PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE62fHuaSP1asZmQ8ikYysNB2VxKd8cV5i
G6WZ7PPD9DKAGoebHzm1D/uT2VEWxtgoZvEkbyhGgBbU5z/aDwIa7YNAIZrrRakV
PTvTEyFY2QbNu96tBlVM78N7Rq2HI8nN
-----END ECDSA PUBLIC KEY-----
`)
func equinoxUpdate() (error, bool) {
opts := equinox.Options{Channel: "stable"}
if err := opts.SetPublicKeyPEM(publicKey); err != nil {
return err, false
}
// check for the update
resp, err := equinox.Check(appID, opts)
switch {
case err == equinox.NotAvailableErr:
fmt.Println("No update available, already at the latest version!")
return nil, false
case err != nil:
fmt.Println("Update failed:", err)
return err, false
}
// fetch the update and apply it
err = resp.Apply()
if err != nil {
return err, false
}
fmt.Printf("Updated to new version: %s!\n", resp.ReleaseVersion)
return nil, true
}
func checkErr(err error) bool {
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
}
return err != nil
}