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 ¶
- Variables
- type Asset
- type Assets
- type Requirements
- type Result
- type Results
- func (m Results) Best() Results
- func (m Results) Errors() []error
- func (m Results) HasErrors() bool
- func (m Results) HasQualified() bool
- func (m Results) IsAmbigious() bool
- func (m Results) Sorted() Results
- func (m Results) Status() (err error)
- func (m Results) Success() bool
- func (m Results) ToString() string
- func (m Results) WithoutZero() Results
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 ¶
Requirements represents the criteria an asset must meet. It includes platform compatibility and a list of hints for name matching.
type Result ¶
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 ¶
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) HasErrors ¶ added in v0.0.13
HasErrors returns true if there are any errors in the results.
func (Results) HasQualified ¶
HasQualified returns true if there's at least one qualified result in the set.
func (Results) IsAmbigious ¶
IsAmbigious returns true if there are multiple qualified results.
func (Results) Sorted ¶
Sorted returns a new sorted instance of Results. It sorts first by qualification status and then by score in descending order.
func (Results) Status ¶
Status evaluates the state of the results and returns an appropriate error if needed.
func (Results) WithoutZero ¶
WithoutZero returns a new instance of Results without zero scores.