go-update: github.com/tj/go-update Index | Examples | Files | Directories

package update

import "github.com/tj/go-update"

Package update provides tooling to auto-update binary releases from GitHub based on the user's current version and operating system.

Code:

// update polls(1) from tj/gh-polls on github
p := &update.Project{
    Command: "polls",
    Owner:   "tj",
    Repo:    "gh-polls",
    Version: "0.0.3",
}

// fetch the new releases
releases, err := p.LatestReleases()
if err != nil {
    log.Fatalf("error fetching releases: %s", err)
}

// no updates
if len(releases) == 0 {
    log.Println("no updates")
    return
}

// latest release
latest := releases[0]

// find the asset for this system
a := latest.FindTarball(runtime.GOOS, runtime.GOARCH)
if a == nil {
    log.Println("no binary for your system")
    return
}

// whitespace
fmt.Println()

path, err := a.DownloadProxy(progress.Reader)
if err != nil {
    log.Fatalf("error downloading: %s", err)
}

// replace the previous
if err := p.Install(path); err != nil {
    log.Fatalf("error installing: %s", err)
}

fmt.Printf("Updated to %s\n", latest.Version)

Index

Examples

Package Files

update.go

Variables

var NopProxy = func(size int, r io.ReadCloser) io.ReadCloser {
    return r
}

NopProxy does nothing.

type Asset Uses

type Asset struct {
    Name      string // Name of the asset.
    Size      int    // Size of the asset.
    URL       string // URL of the asset.
    Downloads int    // Downloads count.
}

Asset represents a project release asset.

func (*Asset) Download Uses

func (a *Asset) Download() (string, error)

Download the asset to a tmp directory and return its path.

func (*Asset) DownloadProxy Uses

func (a *Asset) DownloadProxy(proxy Proxy) (string, error)

DownloadProxy the asset to a tmp directory and return its path.

type Project Uses

type Project struct {
    Command string // Command is the executable's name.
    Owner   string // Owner is the GitHub owner name.
    Repo    string // Repo is the GitHub repo name.
    Version string // Version is the local version.
}

Project represents the project.

func (*Project) Install Uses

func (p *Project) Install(path string) error

Install binary to replace the current version.

func (*Project) InstallTo Uses

func (p *Project) InstallTo(path, dir string) error

InstallTo binary to the given dir.

func (*Project) LatestReleases Uses

func (p *Project) LatestReleases() (latest []*Release, err error)

LatestReleases returns releases newer than Version, or nil.

type Proxy Uses

type Proxy func(int, io.ReadCloser) io.ReadCloser

Proxy is used to proxy a reader, for example using https://github.com/cheggaaa/pb to provide progress updates.

type Release Uses

type Release struct {
    Version     string    // Version is the release version.
    Notes       string    // Notes is the markdown release notes.
    URL         string    // URL is the notes url.
    PublishedAt time.Time // PublishedAt is the publish time.
    Assets      []*Asset  // Assets is the release assets.
    // contains filtered or unexported fields
}

Release represents a project release.

func (*Release) FindTarball Uses

func (r *Release) FindTarball(os, arch string) *Asset

FindTarball returns a tarball matching os and arch, or nil.

Directories

PathSynopsis
_example
progressPackage progress provides a proxy for download progress.

Package update imports 15 packages (graph) and is imported by 1 packages. Updated 2017-07-08. Refresh now. Tools for package owners.