version

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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