goupdate

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 12 Imported by: 6

README

goupdate

Goupdate 是用 Go 语言开发的工具,能够自动从 GitHub 和 Gitee 下载最新的发布版本,并更新本地程序。

本程序是基于 https://github.com/tj/go-update 进行的分支,进行了额外功能的增强。

更新 github

package main

import (
	"github.com/zan8in/gologger"
	"github.com/zan8in/goupdate"
	"github.com/zan8in/goupdate/stores/github"
)

func main() {

	owner := "zan8in"
	repo := "afrog"
	version := "2.8.1"

	if result, err := github.Update(owner, repo, version); err != nil {
		gologger.Error().Msg(err.Error())
	} else {
		if result.Status == 2 {
			gologger.Info().Msgf("%s %s", repo, goupdate.LatestVersionTips)
		} else {
			gologger.Info().Msgf("Successfully updated to %s %s\n", repo, result.LatestVersion)
		}
	}

}

更新 gitee

package main

import (
	"github.com/zan8in/gologger"
	"github.com/zan8in/goupdate"
	"github.com/zan8in/goupdate/stores/gitee"
)

func main() {

	owner := "zanbin"
	repo := "afrog"
	version := "2.8.9"

	if result, err := gitee.Update(owner, repo, version); err != nil {
		gologger.Error().Msg(err.Error())
	} else {
		if result.Status == 2 {
			gologger.Info().Msgf("%s %s", repo, goupdate.LatestVersionTips)
		} else {
			gologger.Info().Msgf("Successfully updated to %s %s\n", repo, result.LatestVersion)
		}
	}

}

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned from GetRelease if the release is not found.
	ErrNotFound = errors.New("release not found")
)

Errors.

View Source
var (
	LatestVersionTips = "is already current and does not need an update"
)
View Source
var NopProxy = func(size int, r io.ReadCloser) io.ReadCloser {
	return r
}

NopProxy does nothing.

Functions

This section is empty.

Types

type Asset

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.
	LatestVersion string
}

Asset represents a project release asset.

func (*Asset) Download

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

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

func (*Asset) DownloadProxy

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

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

type Manager

type Manager struct {
	Store          // Store for releases such as Github or a custom private store.
	Command string // Command is the executable's name.
}

Manager is the update manager.

func (*Manager) Install

func (m *Manager) Install(path string) error

Install binary to replace the current version.

func (*Manager) InstallTo

func (m *Manager) InstallTo(path, dir string) error

InstallTo binary to the given dir.

type Proxy

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

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.
}

Release represents a project release.

func (*Release) FindTarball

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

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

func (*Release) FindZip

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

FindZip returns a zipfile matching os and arch, or nil.

type Store

type Store interface {
	GetRelease(version string) (*Release, error)
	LatestReleases() ([]*Release, error)
}

Store is the interface used for listing and fetching releases.

Directories

Path Synopsis
_example
gitee command
github command
specific command
Package progress provides a proxy for download progress.
Package progress provides a proxy for download progress.
stores
apex
Package apex provides an Apex release store.
Package apex provides an Apex release store.
github
Package github provides a GitHub release store.
Package github provides a GitHub release store.

Jump to

Keyboard shortcuts

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