Documentation ¶
Index ¶
- Variables
- func Apply(update io.Reader, targetPath string, targetMode os.FileMode) error
- func RegisterFormat(name string, extractor Extractor)
- func SelfUpdate(release Release) error
- func StableRelease(_ string, draft bool, preRelease bool) bool
- type AssetFilter
- type BinaryFilter
- type Extractor
- type GithubLocator
- type HTTPDownloader
- type Release
- type ReleaseDownloader
- type ReleaseFilter
- type ReleaseLocator
- type RollbackErr
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoRepository error is returned is the repository is not found or user token has no access to it ErrNoRepository = errors.New("no repository") )
Functions ¶
func Apply ¶
Apply performs an update of the current executable (or opts.TargetFile, if set) with the contents of the given io.Reader.
Apply performs the following actions to ensure a safe cross-platform update:
- Creates a new file, /path/to/.target.new with the TargetMode with the contents of the updated file
- Renames /path/to/target to /path/to/.target.old
- Renames /path/to/.target.new to /path/to/target
- If the final rename is successful, deletes /path/to/.target.old, returns no error. On Windows, the removal of /path/to/target.old always fails, so instead Apply hides the old file instead.
- If the final rename fails, attempts to roll back by renaming /path/to/.target.old back to /path/to/target.
If the roll back operation fails, the file system is left in an inconsistent state where there is no new executable file and the old executable file could not be be moved to its original location. In this case you should notify the user of the bad news and ask them to recover manually. Applications can determine whether the rollback failed by calling RollbackError, see the documentation on that function for additional detail.
func RegisterFormat ¶
RegisterFormat adds a supported archive format
func SelfUpdate ¶
SelfUpdate update the current executable to the release
Types ¶
type AssetFilter ¶
AssetFilter is a function that will filter out unsupported assets for the current system
type BinaryFilter ¶
BinaryFilter is a function used to check if a given path/file is the binary needed
type Extractor ¶
type Extractor interface { // Match checks supported files Match(filename string) bool // FetchBinary reads an archive and find return the reader for the binary based on the filter FetchBinary(input io.Reader, isBinary BinaryFilter) (io.Reader, error) }
Extractor represent a archive extractor
func MatchingExtractor ¶
MatchingExtractor returns the first extractor that matches the given file, or nil if there is no match
type GithubLocator ¶
type GithubLocator struct {
// contains filtered or unexported fields
}
GithubLocator struct encapsulates information about github repo
func NewGithubClient ¶
func NewGithubClient( owner string, repository string, token string, releaseFilter ReleaseFilter, assetFilter AssetFilter, connectionTimeout time.Duration, ) *GithubLocator
NewGithubClient creates new github locator instance
func (*GithubLocator) ListReleases ¶
func (g *GithubLocator) ListReleases(amount int) ([]Release, error)
ListReleases returns available GH releases list
type HTTPDownloader ¶
type HTTPDownloader struct {
// contains filtered or unexported fields
}
HTTPDownloader represents http downloader client
func NewHTTPDownloader ¶
func NewHTTPDownloader(client *http.Client) *HTTPDownloader
NewHTTPDownloader creates new http downloader client instance. If the passed client is nil http.DefaultClient is used.
func (*HTTPDownloader) Fetch ¶
func (d *HTTPDownloader) Fetch(r Release) (io.ReadCloser, error)
Fetch downloads GH release
type Release ¶
type Release struct { // Name the name of the release. In most cases this will be the version number Name string // Assert the name of the asset related to the URL Asset string // URL the download location of the Asset URL string }
Release contains information about a release for the current system
func LatestRelease ¶
func LatestRelease(locator ReleaseLocator) (Release, error)
LatestRelease retrieve the latest release from the locator using semver
func SelfUpdateToLatest ¶
func SelfUpdateToLatest(locator ReleaseLocator) (Release, error)
SelfUpdateToLatest update the current executable to it's latest version
type ReleaseDownloader ¶
type ReleaseDownloader interface { // Fetch downloads the release Fetch(r Release) (io.ReadCloser, error) }
ReleaseDownloader describes a way to download/load a release
var ( // ErrNoRelease error is returned in case no available releases were found. ErrNoRelease = errors.New("no releases were found") // DefaultDownloader the default downloaded to use. DefaultDownloader ReleaseDownloader )
type ReleaseFilter ¶
ReleaseFilter is a function that will filter out releases. This is very useful when you want to support stable, beta and dev channels.
type ReleaseLocator ¶
ReleaseLocator describing a release locator that will fetch releases. A release locator should use the ReleaseFilter and AssetFilter during initialization.
type RollbackErr ¶
type RollbackErr struct { // RollbackErr the error encountered while rolling back RollbackErr error // contains filtered or unexported fields }
RollbackErr represents an error occurred during rollback operation