Documentation
¶
Overview ¶
Package semver provides semantic versioning utilities with support for partial version matching (e.g., "2.1" matches "2.1.x").
Index ¶
- func Compare(a, b *Version) int
- func FilterValid(versions []string) []string
- func IsValid(s string) bool
- func Match(versions []string, target string) (string, bool)
- func Sort(versions []*Version)
- func SortDesc(versions []*Version)
- func SortStrings(versions []string) []string
- func SortStringsDesc(versions []string) []string
- type Version
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare compares two versions. Returns -1 if a < b, 0 if a == b, 1 if a > b. Prereleases are considered lower than releases (1.0.0-alpha < 1.0.0).
func FilterValid ¶
FilterValid returns only valid semver strings from the input slice.
func Match ¶
Match finds the best matching version for a target pattern. The target can be a full version ("2.1.3") or partial ("2.1" or "2"). Returns the highest version that matches the pattern. Prereleases are excluded unless the target is an exact match.
func SortDesc ¶
func SortDesc(versions []*Version)
SortDesc sorts a slice of versions in descending order.
func SortStrings ¶
SortStrings sorts version strings in ascending order. Invalid versions are filtered out.
func SortStringsDesc ¶
SortStringsDesc sorts version strings in descending order. Invalid versions are filtered out.
Types ¶
type Version ¶
type Version struct {
Major int // Major version number (required)
Minor int // Minor version number (-1 if unspecified)
Patch int // Patch version number (-1 if unspecified)
Prerelease string // Prerelease identifier (e.g., "alpha", "beta.1")
Build string // Build metadata (e.g., "build.123")
Original string // Original string representation
}
Version represents a parsed semantic version. Supports partial versions where Minor or Patch may be unspecified (-1).
func MustParse ¶
MustParse parses a semver string and panics on error. Use only for known-good version strings.
func Parse ¶
Parse parses a semver string into a Version struct. Supports partial versions: "2", "2.1", "2.1.3", "2.1.3-beta+build"
func (*Version) HasPrerelease ¶
HasPrerelease returns true if a prerelease identifier is present.