Help us shape the future of Go! Take the 2026 Go Developer Survey

version

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterByMultiple

func FilterByMultiple(versions []string, specifiers []*Specifier) ([]string, error)

FilterByMultiple filters versions by multiple specifiers (all must match)

func IncrementMajor added in v0.6.0

func IncrementMajor(currentVersion string) string

IncrementMajor returns the next major version, preserving the original format. Examples: "1" -> "2", "1.0" -> "2.0", "1.0.0" -> "2.0.0" If the version cannot be parsed, returns "2" as a fallback.

func SelectBest

func SelectBest(versions []string) (string, error)

SelectBest selects the best (highest) version from a list

func Sort added in v0.6.0

func Sort(versions []string) []string

Sort sorts a list of version strings in ascending order (oldest first) using semantic versioning rules. Invalid versions are placed at the end in their original order.

Types

type Specifier

type Specifier struct {
	Operator string
	Version  *Version
}

Specifier represents a version specifier (e.g., ">=1.2.3")

func ParseMultipleSpecifiers

func ParseMultipleSpecifiers(spec string) ([]*Specifier, error)

ParseMultipleSpecifiers parses comma-separated specifiers (e.g., ">=1.0,<2.0")

func ParseSpecifier

func ParseSpecifier(spec string) (*Specifier, error)

ParseSpecifier parses a version specifier

func (*Specifier) Filter

func (s *Specifier) Filter(versions []string) ([]string, error)

Filter filters a list of version strings by the specifier

func (*Specifier) Matches

func (s *Specifier) Matches(v *Version) bool

Matches checks if a version matches the specifier

type Version

type Version struct {
	Major int
	Minor int
	Patch int
	Pre   string // Pre-release suffix (e.g., "alpha", "beta")
	Build string // Build metadata (e.g., "+20250120")
}

Version represents a semantic version

func Parse

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

Parse parses a semantic version string

func (*Version) Compare

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

Compare compares two versions Returns -1 if v < other, 0 if v == other, 1 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