Documentation ¶
Index ¶
- Variables
- func GetYesOrNoInput(ctx context.Context) (bool, error)
- func NeedsUpdate(ctx context.Context, log logrus.FieldLogger, repo, version string, ...) booldeprecated
- func UseUpdater(ctx context.Context, opts ...Option) (*updater, error)
- type Github
- func (g *Github) Check(ctx context.Context) error
- func (g *Github) DownloadRelease(ctx context.Context, r *github.RepositoryRelease, assetName, execName string) (downloadedBinary string, cleanup func(), err error)
- func (g *Github) GetLatestVersion(ctx context.Context, currentVersion string, includePrereleases bool) (*github.RepositoryRelease, error)
- func (g *Github) GetRelease(ctx context.Context, version string) (*github.RepositoryRelease, error)
- func (g *Github) ReplaceRunning(ctx context.Context, newBinary string) error
- func (g *Github) SelectAsset(ctx context.Context, assets []*github.ReleaseAsset, name string) (string, *github.ReleaseAsset, error)
- type Option
- func WithApp(app *cli.App) Option
- func WithCheckInterval(interval time.Duration) Option
- func WithDisabled(disabled bool) Option
- func WithForceCheck(forceCheck bool) Option
- func WithLogger(logger logrus.FieldLogger) Option
- func WithPrereleases(prereleases bool) Option
- func WithRepo(repo string) Option
- func WithVersion(version string) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoNewRelease = errors.New("no new release") ErrNoAsset = errors.New("no asset found") ErrMissingFile = errors.New("file missing in archive") AssetSeperators = []string{"_", "-"} AssetExtensions = []string{".tar.xz", ".tar.gz", ""} )
var Disabled bool
Disabled globally disables the automatic updater. This is helpful for when using an external package manager, such as brew. This should usually be done with an ldflag.
Functions ¶
func GetYesOrNoInput ¶
GetYesOrNoInput returns true if the user selected yes
func NeedsUpdate
deprecated
func NeedsUpdate(ctx context.Context, log logrus.FieldLogger, repo, version string, disabled, debugLog, includePrereleases, forceCheck bool) bool
Deprecated: Use UseUpdater instead. NeedsUpdate is a deprecated method of UseUpdater.
Example ¶
package main import ( "context" "os" "github.com/getoutreach/gobox/pkg/updater" "github.com/sirupsen/logrus" ) func main() { if updater.NeedsUpdate(context.Background(), logrus.New(), "", "v1.0.0", false, false, false, false) { // Stop to use the newer version os.Exit(0) } }
Output:
Types ¶
type Github ¶
type Github struct { // Configuration Options Silent bool // contains filtered or unexported fields }
func NewGithubUpdater
deprecated
func NewGithubUpdaterWithClient ¶
func NewGithubUpdaterWithClient(ctx context.Context, client *github.Client, org, repo string) *Github
NewGithubUpdaterWithClient creates a new updater with the provided Github Client
func (*Github) DownloadRelease ¶
func (g *Github) DownloadRelease(ctx context.Context, r *github.RepositoryRelease, assetName, execName string) (downloadedBinary string, cleanup func(), err error)
DownloadRelease attempts to download a binary from a release.
If the asset found is an archive, it'll be extracted and the value of `execName` will be used to pull a file out of the root of the archive. If `execName` is not provided it is inferred as the name of the currently running basename of the running executable. The downloaded file is returned as `downloadedBinary` with a cleanup function being returned to remove all leftover data.
The cleanup function should be called even when an error occurs
func (*Github) GetLatestVersion ¶
func (g *Github) GetLatestVersion(ctx context.Context, currentVersion string, includePrereleases bool) (*github.RepositoryRelease, error)
GetLatestVersion finds the latest release, based on semver, of a Github Repository (supplied when client was created). This is determined by the following algorithm:
Finding new release:
Github releases are then streaming evaluated to find the currentVersion. All releases that are not == to the current version end up being stored in memory as "candidates" for being evaluated as a possible new version. If the current version is not found then it is ignored.
Including pre-releases:
If the current version is a pre-release: - pre-releases are considered If includePrereleases is true - pre-releases are considered
Selecting a new version:
Once the current releases has been found (or not found) then all versions found before it are considered as candidates and checked to see if a newer release exists. Using the aforementioned pre-release logic pre-releases are included based on that.
func (*Github) GetRelease ¶
GetRelease finds a release with a given version (tag)
func (*Github) ReplaceRunning ¶
ReplaceRunning replaces the running executable with the specified path. This path is renamed to the current executable.
The running process is replaced with a new invocation of the new binary.
func (*Github) SelectAsset ¶
func (g *Github) SelectAsset(ctx context.Context, assets []*github.ReleaseAsset, name string) (string, *github.ReleaseAsset, error)
SelectAsset finds an asset on a Github Release. Returned is the URL to download it and the asset itself. This looks up the following file patterns: - name_GOOS_GOARCH - name_version_GOOS_GOARCH - name_GOOS_GOARCH.tar.gz - name_version_GOOS_GOARCH.tar.gz
type Option ¶ added in v1.39.0
type Option func(*updater)
Options configures an updater
func WithApp ¶ added in v1.39.0
func WithApp(app *cli.App) Option
WithApp sets the cli.App to setup commands on.
func WithCheckInterval ¶ added in v1.39.0
WithCheckInterval sets the interval to check for updates. Defaults to 30 minutes.
func WithDisabled ¶ added in v1.39.0
WithDisabled sets if we should disable the updater or not
func WithForceCheck ¶ added in v1.39.0
WithForceCheck sets whether or not to force the updater to check for updates otherwise updates are checked for only if the last check was more than the update check interval.
func WithLogger ¶ added in v1.39.0
func WithLogger(logger logrus.FieldLogger) Option
WithLogger sets the logger to use for logging. If not set a io.Discard logger is created.
func WithPrereleases ¶ added in v1.39.0
WithPrereleases sets whether or not to include prereleases in the update check.
func WithRepo ¶ added in v1.39.0
WithRepo sets the repository to use for checking for updates. The expected format is: owner/repo
func WithVersion ¶ added in v1.39.0
WithVersion sets the version to use as the current version when checking for updates. Defaults to app.Info().Version.