Documentation
¶
Overview ¶
Package winget provides a client for programmatic access to WinGet package metadata from the microsoft/winget-pkgs repository.
Index ¶
- Variables
- func IsCloneFailed(err error) bool
- func IsIndexBuildFailed(err error) bool
- func IsNotFound(err error) bool
- func IsPullFailed(err error) bool
- type Client
- type ClientOption
- func WithAutoRefresh(interval time.Duration) ClientOption
- func WithCacheDir(dir string) ClientOption
- func WithCloneDepth(depth int) ClientOption
- func WithLogger(logger *zap.Logger) ClientOption
- func WithRepoURL(url string) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- func WithWorkerCount(n int) ClientOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCloneFailed is returned when the initial repository clone fails. ErrCloneFailed = errors.New("repository clone failed") // ErrPullFailed is returned when a git pull / refresh operation fails. ErrPullFailed = errors.New("repository pull failed") // ErrIndexBuildFailed is returned when building the in-memory index fails. ErrIndexBuildFailed = errors.New("index build failed") )
Sentinel errors for client-level failures.
Functions ¶
func IsCloneFailed ¶
IsCloneFailed reports whether err (or any error in its chain) indicates a failure during initial repository cloning.
func IsIndexBuildFailed ¶
IsIndexBuildFailed reports whether err (or any error in its chain) indicates a failure during in-memory index construction.
func IsNotFound ¶
IsNotFound reports whether err (or any error in its chain) indicates that the requested package or version was not found in the index.
func IsPullFailed ¶
IsPullFailed reports whether err (or any error in its chain) indicates a failure during repository pull / refresh.
Types ¶
type Client ¶
type Client struct {
// Packages exposes GetByID, GetByIDAndVersion, GetByName, ListAll,
// ListByPublisher, and Search.
Packages *packages.Packages
// Versions exposes ListByID and GetByIDAndVersion.
Versions *versions.Versions
// Manifests exposes low-level access to individual manifest files.
Manifests *manifests.Manifests
// contains filtered or unexported fields
}
Client is the top-level entry point for the WinGet library. It manages the local repository clone, the in-memory index, and all service objects.
Construct one with NewClient; call Refresh to pull the latest package data.
func NewClient ¶
func NewClient(cfg *config.Config, opts ...ClientOption) (*Client, error)
NewClient creates and initialises a WinGet client. It clones the repository (if not already present) and builds the in-memory package index before returning.
Pass functional options to override configuration defaults:
client, err := winget.NewClient(&config.Config{},
winget.WithCacheDir("~/.cache/winget"),
winget.WithAutoRefresh(24*time.Hour),
)
func NewClientWithExecutor ¶
NewClientWithExecutor creates a client using a custom Executor implementation. This is primarily used in tests where a mock executor is injected.
type ClientOption ¶
ClientOption is a functional option that modifies the client configuration before the client is initialised.
func WithAutoRefresh ¶
func WithAutoRefresh(interval time.Duration) ClientOption
WithAutoRefresh configures the client to automatically pull the latest changes when the local clone is older than the given interval. Pass 0 to disable auto-refresh (the default).
func WithCacheDir ¶
func WithCacheDir(dir string) ClientOption
WithCacheDir sets the local directory used to clone and cache the WinGet repository. The directory is created if it does not exist.
func WithCloneDepth ¶
func WithCloneDepth(depth int) ClientOption
WithCloneDepth controls the shallow-clone depth. Use 0 for a full clone or 1 (the default) for a shallow clone that fetches only the latest commit.
func WithLogger ¶
func WithLogger(logger *zap.Logger) ClientOption
WithLogger sets a custom zap logger. When not provided, a production logger writing JSON to stderr is created automatically. Pass zap.NewNop() to suppress all log output.
func WithRepoURL ¶
func WithRepoURL(url string) ClientOption
WithRepoURL overrides the Git URL of the WinGet packages repository. Defaults to "https://github.com/microsoft/winget-pkgs".
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the maximum duration for clone or pull operations. Defaults to 5 minutes.
func WithWorkerCount ¶
func WithWorkerCount(n int) ClientOption
WithWorkerCount sets the number of goroutines used during index construction. Defaults to runtime.NumCPU().
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config defines configuration for the WinGet library client.
|
Package config defines configuration for the WinGet library client. |
|
Package executor abstracts git repository operations and filesystem access.
|
Package executor abstracts git repository operations and filesystem access. |
|
mock
Package mock provides an in-memory Executor implementation for unit tests.
|
Package mock provides an in-memory Executor implementation for unit tests. |
|
Package index provides the in-memory index of WinGet packages.
|
Package index provides the in-memory index of WinGet packages. |
|
services
|
|
|
manifests
Package manifests provides types and functions for reading and parsing WinGet manifest YAML files.
|
Package manifests provides types and functions for reading and parsing WinGet manifest YAML files. |
|
packages
Package packages provides the primary query surface for WinGet packages.
|
Package packages provides the primary query surface for WinGet packages. |
|
versions
Package versions provides access to the available versions of WinGet packages.
|
Package versions provides access to the available versions of WinGet packages. |
|
shared
|
|
|
models
Package models contains shared types used across the winget library.
|
Package models contains shared types used across the winget library. |