selfupdate

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHashMismatch    = errors.New("new file hash mismatch after patch")
	ErrInvalidHash     = errors.New("invalid hash in update info")
	ErrChannelMismatch = errors.New("update channel mismatch")
	ErrNoRequester     = errors.New("no HTTP requester configured")
)

Common errors

Functions

This section is empty.

Types

type DailyScheduler

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

DailyScheduler implements UpdateScheduler for updates at a specific hour

func NewDailyScheduler

func NewDailyScheduler(hour int) *DailyScheduler

NewDailyScheduler creates a scheduler that runs once per day at the specified hour

func (*DailyScheduler) NextUpdate

func (s *DailyScheduler) NextUpdate() time.Time

func (*DailyScheduler) SetNextUpdate

func (s *DailyScheduler) SetNextUpdate()

func (*DailyScheduler) ShouldUpdate

func (s *DailyScheduler) ShouldUpdate(currentVersion string, forceCheck bool) bool

type HTTPRequester

type HTTPRequester struct{}

HTTPRequester is the normal requester that is used and does an HTTP to the URL location requested to retrieve the specified data.

func (*HTTPRequester) Fetch

func (httpRequester *HTTPRequester) Fetch(url string) (io.ReadCloser, error)

Fetch will return an HTTP request to the specified url and return the body of the result. An error will occur for a non 200 status code.

type IntervalScheduler

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

IntervalScheduler implements UpdateScheduler for updates at fixed intervals

func NewIntervalScheduler

func NewIntervalScheduler(checkTime, randomizeTime int) *IntervalScheduler

NewIntervalScheduler creates a scheduler that runs at fixed intervals with optional randomization

func (*IntervalScheduler) NextUpdate

func (s *IntervalScheduler) NextUpdate() time.Time

func (*IntervalScheduler) SetNextUpdate

func (s *IntervalScheduler) SetNextUpdate()

func (*IntervalScheduler) ShouldUpdate

func (s *IntervalScheduler) ShouldUpdate(currentVersion string, forceCheck bool) bool

type Requester

type Requester interface {
	Fetch(url string) (io.ReadCloser, error)
}

Requester interface allows developers to customize the method in which requests are made to retrieve the version and binary.

type UpdateInfo

type UpdateInfo struct {
	Version string
	Sha256  []byte
	Channel string
	Date    time.Time
}

UpdateInfo contains metadata about an available update

type UpdateScheduler

type UpdateScheduler interface {
	// ShouldUpdate returns true if an update should be performed now
	ShouldUpdate(currentVersion string, forceCheck bool) bool
	// SetNextUpdate schedules the next update time
	SetNextUpdate()
	// NextUpdate returns when the next update is scheduled
	NextUpdate() time.Time
}

UpdateScheduler defines how update timing is handled

type Updater

type Updater struct {
	CurrentVersion     string
	ApiURL             string
	CmdName            string
	BinURL             string
	DiffURL            string
	Dir                string
	ForceCheck         bool
	Scheduler          UpdateScheduler
	Requester          Requester
	Channel            string
	Info               UpdateInfo
	OnSuccessfulUpdate func()
}

Updater handles the self-update process

func (*Updater) NextUpdate

func (u *Updater) NextUpdate() time.Time

func (*Updater) Update

func (u *Updater) Update(ctx context.Context) error

Update performs the self-update process

func (*Updater) UpdateIfNeeded

func (u *Updater) UpdateIfNeeded() error

UpdateIfNeeded starts the update check and apply cycle

Jump to

Keyboard shortcuts

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