version

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

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

func TranslateMavenVersion(mavenVersion string) (string, error)

TranslateMavenVersion handles concrete versions (no ranges). For now we just return the value unchanged.

func TranslateMavenVersionRange added in v1.1.0

func TranslateMavenVersionRange(mavenRange string) (results []string, err error)

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.

func Parse

func Parse(rawVersion string, allowWildcards bool) (Version, error)

Parse parses a string into the most appropriate Version type. It attempts to parse as a SemanticVersion first and falls back to a StringVersion.

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

type VersionInterval struct {
	Min          Version
	MinInclusive bool
	Max          Version
	MaxInclusive bool
}

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 Any

func Any() *VersionPredicate

Any returns a predicate that matches any version.

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.

Jump to

Keyboard shortcuts

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