uptd

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

Up To Date Build Status

uptd (shorthand for up to date) is a Go package which provides primitives and mechanisms to check if a version is up to date according to the latest one published in a remote artifact repository.

Installation

To download the source, run: go get github.com/elastic/uptd.

Usage


import (
    "fmt"

    "github.com/elastic/uptd"
)

func main() {
    var githubToken = "your personal github token"

    provider, err := uptd.NewGithubProvider("elastic", "go-licenser", githubToken)
    if err != nil {
        panic(err)
    }

    uptodate, err := uptd.New(provider, version)
    if err != nil {
        panic(err)
    }

    res, err := uptodate.Check()
    if err != nil {
        panic(err)
    }

    if res.NeedsUpdate {
        fmt.Printf(
            "new version %s available, release URL is %s",
            res.Latest.Version.String(), res.Latest.URL,
        )
    }
}

Contributing

See CONTRIBUTING.md.

Documentation

Overview

Package uptd provides an interface and implementation for checking if there's a newer version available in a remote artifact repository.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResponse

type CheckResponse struct {
	NeedsUpdate bool
	Current     semver.Version
	Latest      LatestResponse
}

CheckResponse is given back by the Check method of an updater.

type GetLatestFunc

type GetLatestFunc func(ctx context.Context, owner, repo string) (*github.RepositoryRelease, *github.Response, error)

GetLatestFunc is used by the GithubProvider to discover newer releases

type GithubProvider

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

GithubProvider is the implementation of an update Provider that is used by the Updater struct

func NewGithubProvider

func NewGithubProvider(owner, repo, token string) (*GithubProvider, error)

NewGithubProvider constructs a new GithubProvider from its parameters.

func (*GithubProvider) Latest

func (u *GithubProvider) Latest() (LatestResponse, error)

Latest queries the remote Github repository to check for a newer version of the executable available.

type LatestResponse

type LatestResponse struct {
	Version    semver.Version
	URL        string
	PreRelease bool
}

LatestResponse is given back by the Latest method of an update Provider.

type Provider

type Provider interface {
	// Latest queries the remote provider to check for a newer version of the
	// executable available in the remote artifact repository.
	Latest() (LatestResponse, error)
}

Provider represents the remote artifact repository where the updater checks if there's a newer version.

type Uptd

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

Uptd checks if the current version is the latest one and thus up to date.

func New

func New(provider Provider, current string) (Uptd, error)

New instantiates a new Uptd from the sent Provider and current version. If the version is not semver compatible an error will be returned.

func (Uptd) Check

func (u Uptd) Check() (CheckResponse, error)

Check checks if there's a newer release available in the remote and returns a response that instructs whether or not the client should download the newer version if any is available.

Jump to

Keyboard shortcuts

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