selfupdate

package
v1.27.3 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Release

type Release struct {
	URL     string          `json:"url"`
	Assets  []*ReleaseAsset `json:"assets"`
	Name    string          `json:"name"`
	TagName string          `json:"tag_name"`
}

Release is a github release.

func (*Release) FindAssetForSystem

func (r *Release) FindAssetForSystem(os string, arch string) *ReleaseAsset

FindAssetForSystem searches returns the asset for the given OS and arch.

func (*Release) Version

func (r *Release) Version() *Version

Version returns the version of the release.

type ReleaseAsset

type ReleaseAsset struct {
	URL                string `json:"url"`
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
}

ReleaseAsset is an asset of a Release.

type Updater

type Updater struct {

	// FetchReleaseFn is used to fetch github release information.
	FetchReleaseFn func(httpClient *http.Client, user string, repo string, tag string) (*Release, error)
	// DownloadFileFn is used to download a file.
	DownloadFileFn func(url string, dest string) error
	// ChmodFn is used to change the permissions of a file.
	ChmodFn func(name string, mode os.FileMode) error
	// ExecuteCmdFn executes the given command and returns the output.
	ExecuteCmdFn func(name string, arg ...string) ([]byte, error)
	// ExecutableFn is used to return the path of the current executable.
	ExecutableFn func() (string, error)
	// RenameFn is used to rename a file.
	RenameFn func(src string, dst string) error
	// RemoveFn is used to remove a file.
	RemoveFn func(path string) error
	// contains filtered or unexported fields
}

Updater provides functionality that allows you to update a binary from github.

func NewUpdater

func NewUpdater(currentVersion string) *Updater

NewUpdater returns an Updater.

func (*Updater) CleanUp

func (u *Updater) CleanUp(path string)

CleanUp cleans up the given path. This should be deferred once a download has completed.

func (*Updater) CurrentVersion

func (u *Updater) CurrentVersion() *Version

CurrentVersion returns the current version.

func (*Updater) DownloadAsset

func (u *Updater) DownloadAsset(asset *ReleaseAsset) (string, error)

DownloadAsset downloads and returns a path to the given asset.

func (*Updater) FindLatestRelease

func (u *Updater) FindLatestRelease() (*Release, error)

FindLatestRelease returns the latest release on the given repo.

func (*Updater) GetVersion

func (u *Updater) GetVersion(path string) (*Version, error)

GetVersion returns the version of the given executable.

func (*Updater) Replace

func (u *Updater) Replace(path string) error

Replace replaces the current executable with the given executable.

type Version

type Version struct {
	Raw   string
	Major int
	Minor int
	Patch int
}

Version is a semver version.

func (*Version) Compare

func (v *Version) Compare(other *Version) int

Compare compares this version to the other version. Returns 1 if newer, -1 if older, 0 if same.

func (*Version) IsDevelopment

func (v *Version) IsDevelopment() bool

IsDevelopment returns true if it's a development version.

func (*Version) String

func (v *Version) String() string

String returns a string representation of the Version.

Jump to

Keyboard shortcuts

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