Documentation
¶
Overview ¶
Package version provides tools for parsing, comparing, and evaluating version strings and predicates. It supports a format similar to Semantic Versioning but with extensions like wildcards (e.g., 1.2.x).
Package version provides tools for parsing, comparing, and evaluating version strings and predicates. It supports a format similar to Semantic Versioning but with extensions like wildcards (e.g., 1.2.x).
Package version provides tools for parsing, comparing, and evaluating version strings and predicates. It supports a format similar to Semantic Versioning but with extensions like wildcards (e.g., 1.2.x).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TranslateMavenVersion ¶ added in v1.1.0
TranslateMavenVersion handles concrete versions (no ranges). For now we just return the value unchanged.
func TranslateMavenVersionRange ¶ added in v1.1.0
TranslateMavenVersionRange converts a Maven-style version range into Fabric-style ranges.
Types ¶
type PredicateTerm ¶
type PredicateTerm struct {
Operator VersionComparisonOperator
Version Version
}
PredicateTerm represents a single part of a predicate string, like ">1.0.0".
func (*PredicateTerm) String ¶
func (term *PredicateTerm) String() string
String reconstructs the term string, omitting the operator for default equality.
type SemanticVersion ¶
type SemanticVersion struct {
// contains filtered or unexported fields
}
SemanticVersion implements a versioning scheme similar to SemVer, supporting components, prerelease tags, and build metadata.
func ParseSemantic ¶
func ParseSemantic(rawVersion string, allowWildcards bool) (*SemanticVersion, error)
ParseSemantic strictly parses a string into a SemanticVersion.
func (*SemanticVersion) Compare ¶
func (sv *SemanticVersion) Compare(other Version) int
func (*SemanticVersion) HasWildcard ¶
func (sv *SemanticVersion) HasWildcard() bool
HasWildcard returns true if the version contains a wildcard component.
func (*SemanticVersion) IsSemantic ¶
func (sv *SemanticVersion) IsSemantic() bool
func (*SemanticVersion) String ¶
func (sv *SemanticVersion) String() string
func (*SemanticVersion) VersionComponent ¶
func (sv *SemanticVersion) VersionComponent(position int) int
VersionComponent returns the numeric value of a version component at a given position. It returns 0 for positions beyond the defined components, unless a wildcard is present.
type StringVersion ¶
type StringVersion struct {
// contains filtered or unexported fields
}
StringVersion is a fallback for non-semantic version strings, with comparison handled by simple string comparison.
func (*StringVersion) Compare ¶
func (sv *StringVersion) Compare(other Version) int
func (*StringVersion) IsSemantic ¶
func (sv *StringVersion) IsSemantic() bool
func (*StringVersion) String ¶
func (sv *StringVersion) String() string
type Version ¶
type Version interface {
fmt.Stringer
// Compare returns -1, 0, or 1 if the receiver is less than, equal to,
// or greater than `other`, respectively.
Compare(other Version) int
// IsSemantic reports whether the version conforms to the semantic structure.
IsSemantic() bool
}
Version is the interface for a comparable version. It can be either a SemanticVersion or a simple StringVersion for non-standard formats.
type VersionComparisonOperator ¶
type VersionComparisonOperator string
VersionComparisonOperator represents a comparison operation.
const ( OpEqual VersionComparisonOperator = "=" OpGreaterOrEqual VersionComparisonOperator = ">=" OpGreater VersionComparisonOperator = ">" OpLessOrEqual VersionComparisonOperator = "<=" OpLess VersionComparisonOperator = "<" OpCaret VersionComparisonOperator = "^" // e.g., ^1.2.3 OpTilde VersionComparisonOperator = "~" // e.g., ~1.2.3 )
type VersionInterval ¶
VersionInterval represents a range of versions, such as [1.0, 2.0). Its fields are public to allow for direct inspection.
func (*VersionInterval) And ¶
func (interval *VersionInterval) And(other *VersionInterval) *VersionInterval
And computes the intersection of this interval with another. If there is no overlap, it returns nil.
func (*VersionInterval) Contains ¶
func (interval *VersionInterval) Contains(version Version) bool
Contains checks if a version is within the interval.
func (*VersionInterval) String ¶
func (interval *VersionInterval) String() string
String returns the mathematical notation of the interval, e.g., "[1.0.0,2.0.0)".
type VersionPredicate ¶
type VersionPredicate struct {
// contains filtered or unexported fields
}
VersionPredicate represents one or more AND-ed predicate terms.
func ParseVersionPredicate ¶
func ParseVersionPredicate(predicateStr string) (*VersionPredicate, error)
ParseVersionPredicate parses a requirement string like ">=1.0.0 <2.0.0" into a predicate.
func (*VersionPredicate) Interval ¶
func (predicate *VersionPredicate) Interval() *VersionInterval
Interval calculates the single VersionInterval that this predicate represents. It returns nil if the predicate is unsatisfiable (e.g., ">2.0 <1.0").
func (*VersionPredicate) String ¶
func (predicate *VersionPredicate) String() string
String reconstructs the original predicate string.
func (*VersionPredicate) Test ¶
func (predicate *VersionPredicate) Test(version Version) bool
Test checks if a version satisfies the predicate.