Help us shape the future of Go! Take the 2026 Go Developer Survey

update

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package update replaces the running binary with the latest GitHub release.

Index

Constants

View Source
const (
	StepCurrent  = "current version"
	StepQuery    = "query latest release"
	StepSelect   = "select asset"
	StepChecksum = "download checksums"
	StepDownload = "download binary"
	StepVerify   = "verify checksum"
	StepInstall  = "install"
	StepDone     = "done"
)

Step names, in the order Run goes through them. Errors from Run name the step that failed ("update failed at <step>: ...").

View Source
const BarWidth = 40

BarWidth is the number of cells in a known-length progress bar.

View Source
const ChunkSize = 256 << 10

ChunkSize is how many bytes one '#' stands for when the length is unknown.

View Source
const DefaultAPIURL = "https://api.github.com/repos/vicgupta/tinyagent/releases/latest"

Variables

This section is empty.

Functions

func Size added in v0.11.0

func Size(n int64) string

Size formats a byte count as B, KiB or MiB.

Types

type JSONReporter added in v0.11.0

type JSONReporter struct{ W io.Writer }

JSONReporter writes each step as a JSONL event {"type":"update.step","step":...,"detail":...} to W, and no progress bar.

func (*JSONReporter) Download added in v0.11.0

func (r *JSONReporter) Download(string, int64) (io.Writer, func())

func (*JSONReporter) Step added in v0.11.0

func (r *JSONReporter) Step(step, detail string)

type ProgressBar added in v0.11.0

type ProgressBar struct {
	W     io.Writer
	Total int64
	// contains filtered or unexported fields
}

ProgressBar draws download progress to W. With Total > 0 it redraws one line, "\r [####....] 42% 1.2 MiB / 2.9 MiB", as bytes arrive; with Total <= 0 it appends one '#' per ChunkSize bytes. Finish ends the line.

func (*ProgressBar) Finish added in v0.11.0

func (p *ProgressBar) Finish()

Finish ends the progress line.

func (*ProgressBar) Write added in v0.11.0

func (p *ProgressBar) Write(b []byte) (int, error)

type Reporter added in v0.11.0

type Reporter interface {
	Step(step, detail string)
	Download(name string, total int64) (io.Writer, func())
}

Reporter receives Run's progress. Step is called once per step with a human-readable detail; Download is called before the binary download and returns a writer fed every byte as it arrives (nil for none) and a finish func called once the body is read or fails.

type StepError added in v0.11.0

type StepError struct {
	Step string
	Err  error
}

StepError is an error from one step of Run.

func (*StepError) Error added in v0.11.0

func (e *StepError) Error() string

func (*StepError) Unwrap added in v0.11.0

func (e *StepError) Unwrap() error

type TextReporter added in v0.11.0

type TextReporter struct {
	W   io.Writer
	Bar bool
}

TextReporter prints one "update: <step>: <detail>" line per step to W. With Bar set (W is a terminal), the download draws a '#' progress bar; otherwise the download prints only plain lines, with no carriage returns.

func (*TextReporter) Download added in v0.11.0

func (r *TextReporter) Download(name string, total int64) (io.Writer, func())

func (*TextReporter) Step added in v0.11.0

func (r *TextReporter) Step(step, detail string)

type Updater

type Updater struct {
	APIURL  string // latest-release endpoint
	Current string // running version, e.g. v0.1.0 or dev
	ExePath string // binary to replace
	Client  *http.Client
	GOOS    string
	GOARCH  string
	Report  Reporter // progress; nil reports nothing
}

func New

func New(current string) (*Updater, error)

func (*Updater) Run

func (u *Updater) Run(ctx context.Context) (string, error)

Run installs the latest release if it is newer than Current and returns a message describing what happened. Each step is reported to u.Report, and an error is a *StepError naming the step that failed.

Jump to

Keyboard shortcuts

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