match

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package match provides functionality to evaluate and match assets against specific platform requirements and name-based hints. It enables scoring assets based on their compatibility with target platforms (e.g., OS, architecture) and their matching patterns, which can include regex or string comparisons.

The core types in this package include Asset, which represents a downloadable file or package, and Requirements, which defines the criteria for matching assets. These criteria can include platform specifications and pattern hints. The Results type facilitates sorting and evaluating the best-matching assets.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMatch is returned when no matches are found.
	ErrNoMatch = errors.New("no matches found")
	// ErrAmbiguous is returned when multiple equally good matches are found.
	ErrAmbiguous = errors.New("ambiguous matches found")
	// ErrNoQualified is returned when no qualified matches are found.
	ErrNoQualified = errors.New("no qualified matches found")
)

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Name     string          // Name is the file name or identifier of the asset.
	Platform detect.Platform // Platform describes the OS, architecture, and other relevant details for compatibility.
}

Asset represents a downloadable file, typically for a specific platform. It includes metadata like the asset name and the platform it targets.

func (Asset) Lower added in v0.0.13

func (a Asset) Lower() string

NameLower returns the asset's name in lowercase. This is useful for case-insensitive matching operations.

func (Asset) Match

func (a Asset) Match(req Requirements) (int, bool, error)

Match evaluates if the asset satisfies the given requirements. It aggregates scores from both platform compatibility and matching hints.

func (*Asset) Parse

func (a *Asset) Parse()

Parse invokes the platform's parsing logic on the asset's name. It populates or derives the platform information from the asset's name.

func (Asset) PlatformMatch

func (a Asset) PlatformMatch(req Requirements) (int, bool)

PlatformMatch evaluates whether the asset's platform matches the required platform. It calculates a score based on the degree of compatibility and returns whether the asset is qualified.

type Assets

type Assets []Asset

Assets is a slice of Asset, representing a collection of downloadable files.

func (Assets) FromNames

func (as Assets) FromNames(names ...string) Assets

FromNames creates a collection of assets from the provided names. It initializes each asset with the given name.

func (Assets) Match

func (as Assets) Match(req Requirements) Results

Match evaluates all assets against the provided requirements and returns a list of results. Each result contains the asset's name, its matching score, and whether it qualifies.

func (Assets) Select

func (as Assets) Select(req Requirements) Results

Select filters and sorts the assets based on the provided requirements. It returns the best matching assets, sorted by score, if any are qualified.

type Requirements

type Requirements struct {
	Hints    hints.Hints
	Platform detect.Platform
}

Requirements represents the criteria an asset must meet. It includes platform compatibility and a list of hints for name matching.

type Result

type Result struct {
	Error     error
	Asset     Asset
	Score     int
	Qualified bool
}

Result represents the outcome of matching an asset. It contains the asset, its score, and whether it is qualified.

type Results

type Results []Result

Results is a collection of Result objects.

func (Results) Best

func (m Results) Best() Results

Best returns the best qualified results based on the highest score. If multiple results have the same best score, they are all returned.

func (Results) Errors added in v0.0.13

func (m Results) Errors() []error

Error returns a combined error from all results.

func (Results) HasErrors added in v0.0.13

func (m Results) HasErrors() bool

HasErrors returns true if there are any errors in the results.

func (Results) HasQualified

func (m Results) HasQualified() bool

HasQualified returns true if there's at least one qualified result in the set.

func (Results) IsAmbigious

func (m Results) IsAmbigious() bool

IsAmbigious returns true if there are multiple qualified results.

func (Results) Sorted

func (m Results) Sorted() Results

Sorted returns a new sorted instance of Results. It sorts first by qualification status and then by score in descending order.

func (Results) Status

func (m Results) Status() (err error)

Status evaluates the state of the results and returns an appropriate error if needed.

func (Results) Success

func (m Results) Success() bool

Success returns true if there is exactly one result.

func (Results) ToString

func (m Results) ToString() string

ToString converts the results into a formatted string for output.

func (Results) WithoutZero

func (m Results) WithoutZero() Results

WithoutZero returns a new instance of Results without zero scores.

Jump to

Keyboard shortcuts

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