github.com/equinox-io/equinox@v1.2.1-0.20200723040547-60ffe7f858fe/README.md (about)

     1  # equinox client SDK [![godoc reference](https://godoc.org/github.com/equinox-io/equinox?status.png)](https://godoc.org/github.com/equinox-io/equinox)
     2  
     3  Package equinox allows applications to remotely update themselves with the [equinox.io](https://equinox.io) service.
     4  
     5  ## Minimal Working Example
     6  
     7  ```go
     8  import "github.com/equinox-io/equinox"
     9  
    10  const appID = "<YOUR EQUINOX APP ID>"
    11  
    12  var publicKey = []byte(`
    13  -----BEGIN PUBLIC KEY-----
    14  MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEtrVmBxQvheRArXjg2vG1xIprWGuCyESx
    15  MMY8pjmjepSy2kuz+nl9aFLqmr+rDNdYvEBqQaZrYMc6k29gjvoQnQ==
    16  -----END PUBLIC KEY-----
    17  `)
    18  
    19  func update(channel string) error {
    20      opts := equinox.Options{Channel: channel}
    21      if err := opts.SetPublicKeyPEM(publicKey); err != nil {
    22          return err
    23      }
    24  
    25      // check for the update
    26      resp, err := equinox.Check(appID, opts)
    27      switch {
    28      case err == equinox.NotAvailableErr:
    29          fmt.Println("No update available, already at the latest version!")
    30          return nil
    31      case err != nil:
    32          return err
    33      }
    34  
    35      // fetch the update and apply it
    36      err = resp.Apply()
    37      if err != nil {
    38          return err
    39      }
    40  
    41      fmt.Printf("Updated to new version: %s!\n", resp.ReleaseVersion)
    42      return nil
    43  }
    44  ```
    45  
    46  
    47  ## Update To Specific Version
    48  
    49  When you specify a channel in the update options, equinox will try to update the application
    50  to the latest release of your application published to that channel. Instead, you may wish to
    51  update the application to a specific (possibly older) version. You can do this by explicitly setting
    52  Version in the Options struct:
    53  
    54  ```go
    55  opts := equinox.Options{Version: "0.1.2"}
    56  ```
    57  
    58  ## Prompt For Update
    59  
    60  You may wish to ask the user for approval before updating to a new version. This is as simple
    61  as calling the Check function and only calling Apply on the returned result if the user approves.
    62  Example:
    63  
    64  ```go
    65  // check for the update
    66  resp, err := equinox.Check(appID, opts)
    67  switch {
    68  case err == equinox.NotAvailableErr:
    69      fmt.Println("No update available, already at the latest version!")
    70      return nil
    71  case err != nil:
    72      return err
    73  }
    74  
    75  fmt.Println("New version available!")
    76  fmt.Println("Version:", resp.ReleaseVersion)
    77  fmt.Println("Name:", resp.ReleaseTitle)
    78  fmt.Println("Details:", resp.ReleaseDescription)
    79  
    80  ok := prompt("Would you like to update?")
    81  
    82  if !ok {
    83      return
    84  }
    85  
    86  err = resp.Apply()
    87  // ...
    88  ```
    89  
    90  ## Generating Keys
    91  
    92  All equinox releases must be signed with a private ECDSA key, and all updates verified with the
    93  public key portion. To do that, you'll need to generate a key pair. The equinox release tool can
    94  generate an ecdsa key pair for you easily:
    95  
    96  ```shell
    97  equinox genkey
    98  ```
    99