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

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