Documentation
¶
Overview ¶
Package wmlupdate is a lightweight, embeddable updater library.
The public surface is deliberately small:
u, err := wmlupdate.New(wmlupdate.Options{
ConfigPath: "updater.json",
CurrentVersion: currentVersion,
})
update, err := u.Check(ctx)
if update.Available {
result, err := u.Apply(ctx, update, wmlupdate.ApplyOptions{})
}
The library owns release discovery, verified download, installation, backup and rollback bookkeeping. It does not start a daemon, require a specific application framework, or control the host process lifecycle. For languages without a native binding, the command in cmd/wml-update exposes the same engine over NDJSON and an optional loopback HTTP API.
Index ¶
- Constants
- Variables
- func Code(err error) string
- type ApplyOptions
- type Asset
- type AssetRule
- type Config
- type DownloadConfig
- type Error
- type Event
- type EventFunc
- type EventType
- type InstallConfig
- type MacOSConfig
- type Options
- type Platform
- type Result
- type SecurityConfig
- type SourceConfig
- type Update
- type Updater
Constants ¶
const ( SourceGitHub = "github" SourceStatic = "static" SourceChain = "chain" )
Source type values.
const ( InstallDirectory = "directory" InstallFile = "file" InstallCommand = "command" InstallExternal = "external" )
Install type values.
const ( StatusUpdated = "updated" StatusDownloaded = "downloaded" StatusApplyScheduled = "apply_scheduled" )
Apply status values.
Variables ¶
var ErrNoUpdate = errors.New("no update available")
ErrNoUpdate is returned when Apply is called without an available update.
Functions ¶
Types ¶
type ApplyOptions ¶
type ApplyOptions struct {
// Defer stages the update and applies it from a detached helper after the
// selected processes exit. Recommended on Windows when the target is
// running, and required when replacing the running updater itself.
Defer bool `json:"defer,omitempty"`
// WaitPIDs lists processes that must exit before a deferred apply.
WaitPIDs []int `json:"wait_pids,omitempty"`
}
ApplyOptions controls installation.
type Asset ¶
type Asset struct {
Name string `json:"name"`
OS string `json:"os"`
Arch string `json:"arch"`
Format string `json:"format,omitempty"`
SHA256 string `json:"sha256,omitempty"`
Size int64 `json:"size,omitempty"`
}
Asset describes the selected platform artifact.
type AssetRule ¶
type AssetRule struct {
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
Match string `json:"match,omitempty"`
Format string `json:"format,omitempty"`
}
AssetRule selects a release asset for a platform. Rules are evaluated in order. Match supports {version}, {tag}, {os}, {arch} and glob wildcards.
type Config ¶
type Config struct {
AppID string `json:"app_id"`
Channel string `json:"channel,omitempty"`
CurrentVersion string `json:"current_version,omitempty"`
Source SourceConfig `json:"source"`
AssetRules []AssetRule `json:"asset_rules,omitempty"`
Install InstallConfig `json:"install"`
StateDir string `json:"state_dir,omitempty"`
Security SecurityConfig `json:"security,omitempty"`
Download DownloadConfig `json:"download,omitempty"`
}
Config is the programmatic form of the updater configuration. It mirrors the updater.json schema but is intentionally limited to the fields an embedding application needs. Use Options.ConfigPath when you want to ship a JSON file with environment expansion and schema support.
type DownloadConfig ¶
type DownloadConfig struct {
MaxBytes int64 `json:"max_bytes,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
Retries int `json:"retries,omitempty"`
Proxy string `json:"proxy,omitempty"`
}
DownloadConfig bounds downloads and retries.
type Event ¶
type Event struct {
Type EventType `json:"type"`
Time time.Time `json:"time"`
Phase string `json:"phase,omitempty"`
Message string `json:"message,omitempty"`
Bytes int64 `json:"bytes,omitempty"`
Total int64 `json:"total,omitempty"`
Percent float64 `json:"percent,omitempty"`
}
Event is delivered to Options.Events. It is a read-only progress/log signal; the terminal result is returned by Check and Apply.
type EventFunc ¶
type EventFunc func(Event)
EventFunc receives progress and log callbacks. It is called synchronously.
type InstallConfig ¶
type InstallConfig struct {
Type string `json:"type"`
Path string `json:"path,omitempty"`
Paths map[string]string `json:"paths,omitempty"`
StripComponents int `json:"strip_components,omitempty"`
Preserve []string `json:"preserve,omitempty"`
FileMode string `json:"file_mode,omitempty"`
KeepBackups int `json:"keep_backups,omitempty"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
WorkDir string `json:"workdir,omitempty"`
Env map[string]string `json:"env,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
RelaunchPath string `json:"relaunch_path,omitempty"`
RelaunchArgs []string `json:"relaunch_args,omitempty"`
MacOS MacOSConfig `json:"macos,omitempty"`
}
InstallConfig controls how a verified artifact is applied.
type MacOSConfig ¶ added in v1.0.0
type MacOSConfig struct {
// RemoveQuarantine removes com.apple.quarantine recursively. This bypasses
// Gatekeeper's first-launch check; enable only for verified updates.
RemoveQuarantine bool `json:"remove_quarantine,omitempty"`
// AdHocSign force-signs the target with an ad-hoc signature. This can make
// unsigned bundles launch, but destroys Developer ID signatures and
// notarization; use only for unsigned distributions.
AdHocSign bool `json:"ad_hoc_sign,omitempty"`
// AllowSignerChange permits a Developer ID team change. By default an
// installed signed .app requires the downloaded app to have the same team.
AllowSignerChange bool `json:"allow_signer_change,omitempty"`
}
MacOSConfig controls optional post-install metadata handling on macOS.
type Options ¶
type Options struct {
// ConfigPath loads a complete updater.json configuration, including
// environment references and $schema support.
ConfigPath string
// Config supplies a programmatic configuration. Set exactly one of
// ConfigPath and Config.
Config *Config
// BaseDir resolves relative paths in a programmatic Config. It defaults to
// the current working directory.
BaseDir string
// CurrentVersion is the running application version. When empty, the
// library falls back to the recorded state and then Config.CurrentVersion.
CurrentVersion string
// Platform overrides the target platform for cross-platform packaging tests.
Platform *Platform
// Events receives progress, log and warning callbacks. It is invoked
// synchronously and should return quickly.
Events EventFunc
}
Options configures an Updater.
type Result ¶
type Result struct {
Status string `json:"status"`
PreviousVersion string `json:"previous_version,omitempty"`
Version string `json:"version,omitempty"`
ArtifactPath string `json:"artifact_path,omitempty"`
PlanID string `json:"plan_id,omitempty"`
HelperPID int `json:"helper_pid,omitempty"`
}
Result describes a completed Apply.
type SecurityConfig ¶
type SecurityConfig struct {
PublicKey string `json:"public_key,omitempty"`
PublicKeyFile string `json:"public_key_file,omitempty"`
ChecksumsAsset string `json:"checksums_asset,omitempty"`
ChecksumsSignatureAsset string `json:"checksums_signature_asset,omitempty"`
AllowedHosts []string `json:"allowed_hosts,omitempty"`
AllowInsecureHTTP bool `json:"allow_insecure_http,omitempty"`
AllowUnverifiedAssets bool `json:"allow_unverified_assets,omitempty"`
}
SecurityConfig controls signature verification and network boundaries.
type SourceConfig ¶
type SourceConfig struct {
Type string `json:"type"`
// Chain tries sources in order until one returns valid metadata.
Sources []SourceConfig `json:"sources,omitempty"`
// GitHub Releases.
Owner string `json:"owner,omitempty"`
Repo string `json:"repo,omitempty"`
APIBase string `json:"api_base,omitempty"`
TagPrefix string `json:"tag_prefix,omitempty"`
TokenEnv string `json:"token_env,omitempty"`
IncludePrerelease bool `json:"include_prerelease,omitempty"`
// Self-hosted static manifest.
ManifestURL string `json:"manifest_url,omitempty"`
ManifestURLs []string `json:"manifest_urls,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
// AssetMirrors are URL templates for download failover.
AssetMirrors []string `json:"asset_mirrors,omitempty"`
}
SourceConfig describes GitHub Releases or a self-hosted manifest.
type Update ¶
type Update struct {
Available bool `json:"available"`
CurrentVersion string `json:"current_version"`
Version string `json:"version"`
Channel string `json:"channel,omitempty"`
Source string `json:"source,omitempty"`
Tag string `json:"tag,omitempty"`
Notes string `json:"notes,omitempty"`
PublishedAt time.Time `json:"published_at,omitempty"`
Mandatory bool `json:"mandatory,omitempty"`
Prerelease bool `json:"prerelease,omitempty"`
Asset Asset `json:"asset"`
// contains filtered or unexported fields
}
Update is the result of Check. Its exported fields are informational. Apply uses an opaque checked snapshot retained by the Updater; do not construct or serialize Update values.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater is a configured, embeddable updater. Check may be called concurrently; Apply takes an inter-process lock and is serialized.
func (*Updater) Apply ¶
Apply installs a release returned by Check. The exact checked release is retained internally, so source metadata is not re-fetched; artifact bytes are still downloaded and verified against the checked SHA-256 before use.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
wml-update
command
Command wml-update is a cross-platform updater for GitHub Releases and self-hosted static manifests.
|
Command wml-update is a cross-platform updater for GitHub Releases and self-hosted static manifests. |
|
examples
|
|
|
go
command
Command example demonstrates embedding the updater library.
|
Command example demonstrates embedding the updater library. |
|
go-cli
command
Command example runs wml-update and consumes its NDJSON event stream.
|
Command example runs wml-update and consumes its NDJSON event stream. |
|
playground
command
Command playground runs a complete local update without any external service.
|
Command playground runs a complete local update without any external service. |
|
internal
|
|
|
api
Package api implements the optional local integration API.
|
Package api implements the optional local integration API. |
|
archive
Package archive safely extracts and creates ZIP and tar archives.
|
Package archive safely extracts and creates ZIP and tar archives. |
|
buildinfo
Package buildinfo holds version metadata injected at build time.
|
Package buildinfo holds version metadata injected at build time. |
|
checksum
Package checksum parses and computes SHA-256 digests.
|
Package checksum parses and computes SHA-256 digests. |
|
config
Package config loads and validates updater configuration.
|
Package config loads and validates updater configuration. |
|
engine
Package engine orchestrates checks, verified downloads, installation, rollback and the JSON-facing result model.
|
Package engine orchestrates checks, verified downloads, installation, rollback and the JSON-facing result model. |
|
event
Package event defines the stable event stream shared by the CLI JSON mode and the local HTTP API.
|
Package event defines the stable event stream shared by the CLI JSON mode and the local HTTP API. |
|
httpx
Package httpx provides a hardened HTTP client, bounded retries and resumable downloads for the updater.
|
Package httpx provides a hardened HTTP client, bounded retries and resumable downloads for the updater. |
|
install
Package install applies verified artifacts transactionally.
|
Package install applies verified artifacts transactionally. |
|
lock
Package lock serializes operations that mutate an installation.
|
Package lock serializes operations that mutate an installation. |
|
manifest
Package manifest defines the self-hosted update manifest format and its detached Ed25519 signature.
|
Package manifest defines the self-hosted update manifest format and its detached Ed25519 signature. |
|
platform
Package platform normalizes operating system and architecture names and selects platform-specific assets.
|
Package platform normalizes operating system and architecture names and selects platform-specific assets. |
|
publish
Package publish builds self-hosted manifests, signed checksum files and release archives from a publish specification.
|
Package publish builds self-hosted manifests, signed checksum files and release archives from a publish specification. |
|
release
Package release contains the normalized release model shared by update sources and the update engine.
|
Package release contains the normalized release model shared by update sources and the update engine. |
|
sign
Package sign implements Ed25519 key generation, detached signatures and public-key loading for update manifests and checksum files.
|
Package sign implements Ed25519 key generation, detached signatures and public-key loading for update manifests and checksum files. |
|
source
Package source fetches normalized release metadata from GitHub Releases or a self-hosted static manifest.
|
Package source fetches normalized release metadata from GitHub Releases or a self-hosted static manifest. |
|
state
Package state persists updater bookkeeping: installed version, update history, backups and an in-flight install journal.
|
Package state persists updater bookkeeping: installed version, update history, backups and an in-flight install journal. |
|
version
Package version implements strict Semantic Versioning 2.0.0 parsing and ordering.
|
Package version implements strict Semantic Versioning 2.0.0 parsing and ordering. |