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 ¶
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) Extension ¶
Extension returns the file extension of the asset based on its name. It maps common file extensions to predefined constants.
func (Asset) Match ¶
func (a Asset) Match(req Requirements) (int, bool)
Match evaluates if the asset satisfies the given requirements. It aggregates scores from both platform compatibility and matching hints.
func (Asset) MatchHint ¶
MatchHint checks if the asset's name matches the provided hint. The hint can be a regular expression or a simple substring match.
func (Asset) NameLower ¶
NameLower returns the asset's name in lowercase. This is useful for case-insensitive matching operations.
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 Hint ¶
type Hint struct {
Pattern string // Pattern to match against the asset's name.
Weight string // Weight used to adjust the score for non-mandatory hints.
Must bool // Indicates if the hint is mandatory for a match.
// contains filtered or unexported fields
}
Hint represents a pattern used to match asset names. It can be a regular expression or a simple string pattern.
type Hints ¶
type Hints []Hint
Hints represents a collection of Hint objects used to evaluate asset matches.
type Requirements ¶
type Requirements struct {
Platform detect.Platform // Platform specifies the required OS, architecture, and library compatibility.
Hints []Hint // Hints contains patterns used to match the asset's name.
}
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 {
Asset Asset // Asset being evaluated.
Score int // Score representing how well the asset matches the requirements.
Qualified bool // Qualified indicates whether the asset meets the necessary criteria.
}
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) 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.