update

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: MIT Imports: 17 Imported by: 0

README

Build Status Go Report GoDoc

GoUpdate

Go Update is a single source file module which brings auto-update capabilities to Go applications.

Implementation

GoUpdate automates checking for version updates from any source using the GitHub release JSON format.

The logic parses the JSON and looks for the "tag_name" to detemine the existance of a new version.

If an update is found, the module will look in the assets array for the first "browser_download_url" JSON key that matches "Current Executable"-"Platform".zip (eg. demo-darwin.zip / demo-linux.zip)

The module will then download the binary using the URL in "browser_download_url" JSON key.

The module expects to download a zip file and finds the first file whos name matches the current executable to use as the replacement executable.

The file is extracted, copied to the location of the currently running executable,

Usage

Refering to the included demo, the application currently offers the following public APIs:

    import "github.com/mlavergn/goupdate/src/update"

    currentVersion := "1.0.0"
    url : = "https://api.github.com/repos/mlavergn/godaemon/releases/latest"
    update := NewUpdate(url)
    // -or-
    // OAuth resource
    update := NewTokenUpdate(url, "A0B1C2D3E4F5A0B1C2D3E4F5A0B1C2D3E4F5")

    // one-time check (eg. on startup)
    release := update.Check(currentVersion)
    if release != nil {
        update.Update(release)
    }
    // -or-
    // auto-update
    intervalInMins := 24 * 60
    update.AutoUpdate(currentVersion, intervalInMins)

Documentation

Index

Constants

View Source
const DEBUG = false

DEBUG flag

View Source
const Version = "0.6.0"

Version export

Variables

This section is empty.

Functions

func Config

func Config(debug bool, logger *oslog.Logger)

Config export

Types

type GitHubAsset

type GitHubAsset struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Download string `json:"browser_download_url"`
}

GitHubAsset export

type GitHubRelease

type GitHubRelease struct {
	Version         string        `json:"tag_name"`
	Assets          []GitHubAsset `json:"assets"`
	Prerelease      bool          `json:"prerelease"`
	SemanticVersion SemanticVersion
}

GitHubRelease export

type SemanticVersion

type SemanticVersion struct {
	Name  string
	Major int
	Minor int
	Patch int
	Path  string
}

SemanticVersion export

func NewSemanticVersion

func NewSemanticVersion(version string) *SemanticVersion

NewSemanticVersion export

func (*SemanticVersion) FullName

func (id *SemanticVersion) FullName() string

FullName export

func (*SemanticVersion) FullPath

func (id *SemanticVersion) FullPath() string

FullPath export

func (*SemanticVersion) IsMoreRecentThan

func (id *SemanticVersion) IsMoreRecentThan(version *SemanticVersion) bool

IsMoreRecentThan export

func (*SemanticVersion) PlatformArchiveName

func (id *SemanticVersion) PlatformArchiveName() string

PlatformArchiveName export

func (*SemanticVersion) SymlinkPath

func (id *SemanticVersion) SymlinkPath() string

SymlinkPath export

type Update

type Update struct {
	// contains filtered or unexported fields
}

Update export

func NewGitHubEnterpriseUpdate

func NewGitHubEnterpriseUpdate(host string, owner string, project string, token string, prerelease bool) *Update

NewGitHubEnterpriseUpdate export

func NewGitHubUpdate

func NewGitHubUpdate(owner string, project string, token string, prerelease bool) *Update

NewGitHubUpdate export

func (*Update) AutoUpdate

func (id *Update) AutoUpdate(current *SemanticVersion, interval time.Duration, restartFunc func(release *SemanticVersion))

AutoUpdate export

func (*Update) Check

func (id *Update) Check(currentVer *SemanticVersion) *GitHubRelease

Check obtains the latest release version from GitHub

func (*Update) RemoveVersion

func (id *Update) RemoveVersion(version *SemanticVersion)

RemoveVersion export

func (*Update) Update

func (id *Update) Update(current *SemanticVersion, release *GitHubRelease) bool

Update obtains the latest release binary from GitHub and writes it to disk

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL