version

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

type Constraint struct {
	Type    ConstraintType
	Version *Version
}

Constraint represents a parsed version constraint.

func ParseConstraint

func ParseConstraint(s string) (*Constraint, error)

ParseConstraint parses a version constraint string. Supported formats: "1.0.0", "^1.0.0", "~1.0.0"

func (*Constraint) FindBestMatch

func (c *Constraint) FindBestMatch(versions []*Version) *Version

FindBestMatch finds the best (highest) matching version from a list. Returns nil if no version matches the constraint.

func (*Constraint) IsExact

func (c *Constraint) IsExact() bool

IsExact returns true if this is an exact version constraint.

func (*Constraint) Matches

func (c *Constraint) Matches(v *Version) bool

Matches returns true if the given version satisfies this constraint.

func (*Constraint) String

func (c *Constraint) String() string

String returns the string representation of the constraint.

type ConstraintType

type ConstraintType int

ConstraintType identifies the type of version constraint.

const (
	// ConstraintExact matches only the exact version (e.g., "1.0.0").
	ConstraintExact ConstraintType = iota
	// ConstraintCaret matches minor-compatible versions (e.g., "^1.0.0" matches >=1.0.0, <2.0.0).
	ConstraintCaret
	// ConstraintTilde matches patch-compatible versions (e.g., "~1.0.0" matches >=1.0.0, <1.1.0).
	ConstraintTilde
)

type Version

type Version struct {
	Major      int
	Minor      int
	Patch      int
	Prerelease string
}

Version represents a parsed semantic version.

func Parse

func Parse(v string) (*Version, error)

Parse parses a version string (e.g., "1.2.3" or "1.2.3-beta.1").

func (*Version) Compare

func (v *Version) Compare(other *Version) int

Compare returns -1 if v < other, 0 if v == other, 1 if v > other. Prerelease versions are considered less than release versions with the same major.minor.patch.

func (*Version) GreaterThanOrEqual

func (v *Version) GreaterThanOrEqual(other *Version) bool

GreaterThanOrEqual returns true if v >= other.

func (*Version) LessThan

func (v *Version) LessThan(other *Version) bool

LessThan returns true if v < other.

func (*Version) String

func (v *Version) String() string

String returns the string representation of the version.

Jump to

Keyboard shortcuts

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