version

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package version provides semantic versioning utilities for the ApertureStack ecosystem.

This package handles version parsing, comparison, compatibility checking, and version negotiation for tool and protocol versions.

Parsing Versions

Parse semantic version strings:

v, err := version.Parse("1.2.3")
v, err := version.Parse("v2.0.0-beta.1+build.123")

Comparing Versions

v1 := version.MustParse("1.0.0")
v2 := version.MustParse("2.0.0")

v1.LessThan(v2)    // true
v1.GreaterThan(v2) // false
v1.Equal(v2)       // false
v1.Compatible(v2)  // false (different major)

Version Constraints

Parse and check version constraints:

c, _ := version.ParseConstraint(">=1.0.0")
c.Check(version.MustParse("1.5.0")) // true
c.Check(version.MustParse("0.9.0")) // false

Supported constraint operators:

  • "=" or "" - exact match
  • ">" - greater than
  • ">=" - greater than or equal
  • "<" - less than
  • "<=" - less than or equal
  • "^" - compatible (same major)
  • "~" - approximately (same major.minor)

Compatibility Matrix

Track version compatibility across components:

matrix := version.NewMatrix()
matrix.Add(version.Compatibility{
    Component:  "toolfoundation",
    MinVersion: version.MustParse("0.1.0"),
})

ok, msg := matrix.Check("toolfoundation", version.MustParse("0.2.0"))

Version Negotiation

Find the best compatible version from available options:

available := []version.Version{
    version.MustParse("1.0.0"),
    version.MustParse("1.1.0"),
    version.MustParse("2.0.0"),
}
best, err := matrix.Negotiate("component", available)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compatibility

type Compatibility struct {
	Component  string
	MinVersion Version
	MaxVersion *Version // nil means no upper bound
	Deprecated bool
	Message    string
}

Compatibility represents version compatibility between components.

type Constraint

type Constraint struct {
	Op      string // "", "=", ">", ">=", "<", "<=", "^", "~"
	Version Version
}

Constraint represents a version constraint (e.g., ">=1.0.0", "^2.0.0").

func ParseConstraint

func ParseConstraint(s string) (Constraint, error)

ParseConstraint parses a version constraint string.

func (Constraint) Check

func (c Constraint) Check(v Version) bool

Check returns true if the given version satisfies the constraint.

func (Constraint) String

func (c Constraint) String() string

String returns the constraint as a string.

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

Matrix holds compatibility information for multiple components.

func NewMatrix

func NewMatrix() *Matrix

NewMatrix creates a new compatibility matrix.

func (*Matrix) Add

func (m *Matrix) Add(comp Compatibility)

Add adds a compatibility entry for a component.

func (*Matrix) Check

func (m *Matrix) Check(component string, v Version) (bool, string)

Check checks if a version is compatible for a component.

func (*Matrix) Negotiate

func (m *Matrix) Negotiate(component string, available []Version) (Version, error)

Negotiate finds the best compatible version from a list.

type Version

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

Version represents a semantic version (major.minor.patch-prerelease+build).

func MustParse

func MustParse(s string) Version

MustParse parses a version string and panics on error.

func Parse

func Parse(s string) (Version, error)

Parse parses a semantic version string.

func (Version) Compare

func (v Version) Compare(other Version) int

Compare returns -1, 0, or 1 if v < other, v == other, or v > other.

func (Version) Compatible

func (v Version) Compatible(other Version) bool

Compatible returns true if v is compatible with other (same major, v >= other).

func (Version) Equal

func (v Version) Equal(other Version) bool

Equal returns true if v == other (ignoring build metadata).

func (Version) GreaterThan

func (v Version) GreaterThan(other Version) bool

GreaterThan 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 version as a string (with v prefix).

Jump to

Keyboard shortcuts

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