update

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package update implements release discovery and secure self-update primitives.

Index

Constants

View Source
const (
	DefaultReleasesURL = "https://api.github.com/repos/Architeg/gloss/releases?per_page=20"
	DefaultUserAgent   = "gloss-updater"
)
View Source
const HomebrewUpgradeCommand = "brew upgrade Architeg/tap/gloss"

Variables

View Source
var ErrUnsupportedPlatform = errors.New("unsupported update platform")

Functions

func InstallVerified

func InstallVerified(layout Layout, verified VerifiedUpdate) error

InstallVerified atomically replaces an eligible manual executable.

func IsHomebrew

func IsHomebrew(err error) bool

IsHomebrew reports whether an error identifies a Homebrew installation.

func ParseChecksums

func ParseChecksums(data []byte, expected string) ([]byte, error)

ParseChecksums returns the expected digest for an exact basename.

func ValidateArchive

func ValidateArchive(data []byte, expectedExecutable string, maxSize uint64) ([]byte, error)

ValidateArchive validates the complete archive before returning executable bytes. It must only be called after checksum verification.

Types

type Asset

type Asset struct {
	Name string
	URL  string
}

Asset is a release asset selected by exact name.

type CheckResult

type CheckResult struct {
	CurrentVersion    string
	CurrentValid      bool
	LatestVersion     string
	UpdateAvailable   bool
	PlatformSupported bool
	Release           Release
}

CheckResult describes a stable release relative to the running version.

type CheckState

type CheckState struct {
	LastCompleted time.Time `json:"last_completed"`
	LatestVersion string    `json:"latest_version,omitempty"`
}

CheckState is the minimal persisted automatic-check state.

type Client

type Client struct {
	HTTP          *http.Client
	ReleasesURL   string
	UserAgent     string
	GOOS          string
	GOARCH        string
	ReleaseMax    int64
	ChecksumMax   int64
	ArchiveMax    int64
	ExecutableMax uint64
}

Client performs update HTTP operations. Fields are injectable for tests.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a client for the running platform.

func (*Client) Check

func (c *Client) Check(ctx context.Context, current string) (CheckResult, error)

Check discovers the highest stable release returned by the configured API.

func (*Client) DownloadVerified

func (c *Client) DownloadVerified(ctx context.Context, release Release) (VerifiedUpdate, error)

DownloadVerified downloads checksums and the platform archive, verifies the archive digest, then validates and reads its sole executable.

type HomebrewError

type HomebrewError struct {
	Path string
}

HomebrewError explains why self-replacement is forbidden.

func (*HomebrewError) Error

func (e *HomebrewError) Error() string

type Layout

type Layout struct {
	Kind     LayoutKind
	Invoked  string
	Path     string
	Mode     os.FileMode
	Platform Platform
	// contains filtered or unexported fields
}

Layout is a validated executable replacement target.

func InspectExecutable

func InspectExecutable(executablePath, goos, goarch string) (Layout, error)

InspectExecutable validates a candidate executable without modifying it.

func InspectRunningExecutable

func InspectRunningExecutable() (Layout, error)

InspectRunningExecutable validates the current executable's installation layout.

type LayoutKind

type LayoutKind int

LayoutKind classifies how the running executable is managed.

const (
	LayoutManual LayoutKind = iota
	LayoutHomebrew
)

type Platform

type Platform struct {
	GOOS       string
	GOARCH     string
	Archive    string
	Executable string
}

Platform is the exact release-asset contract for one supported target.

func PlatformFor

func PlatformFor(goos, goarch string) (Platform, error)

PlatformFor returns the exact asset mapping for a supported target.

type Release

type Release struct {
	Tag       string
	Version   Version
	Platform  Platform
	Archive   Asset
	Checksums Asset
}

Release is the selected stable release and its required assets.

type StateStore

type StateStore struct {
	Path string
	Now  func() time.Time
}

StateStore persists automatic-check state beside other Gloss-owned data.

func (StateStore) Due

func (s StateStore) Due(interval time.Duration) bool

Due reports whether an automatic check should run. Missing or malformed state is treated as due so it can never prevent application startup.

func (StateStore) Load

func (s StateStore) Load() (CheckState, error)

Load reads state without changing it.

func (StateStore) MarkCompleted

func (s StateStore) MarkCompleted(latest string) (retErr error)

MarkCompleted atomically records a successful release check.

type VerifiedUpdate

type VerifiedUpdate struct {
	Version        string
	ExecutableName string
	Data           []byte
	Platform       Platform
}

VerifiedUpdate contains an archive payload only after checksum and ZIP validation have both succeeded.

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version is a stable three-component semantic version.

func ParseVersion

func ParseVersion(value string) (Version, error)

ParseVersion accepts an optional leading v and rejects prerelease, build-metadata, and incomplete versions.

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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