version

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package version provides semantic version parsing and manipulation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareVersions added in v1.1.0

func CompareVersions(a, b string) (int, error)

CompareVersions compares two version strings and returns their relative ordering. It returns -1 if a < b, 0 if a == b, and 1 if a > b. If either version string cannot be parsed, an error is returned with context indicating which version failed to parse.

func IsGreaterE added in v1.1.0

func IsGreaterE(a, b string) (bool, error)

IsGreaterE returns true if version a is greater than version b, along with any error that occurred during parsing. This is the preferred function for new code as it allows callers to distinguish between "version A is not greater" and "invalid version string".

If an error is returned, the boolean result should be ignored.

Types

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version represents a semantic version.

func Parse

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

Parse parses a semantic version string.

func (*Version) Bump

func (v *Version) Bump(bumpType string) (*Version, error)

Bump returns a new version with the specified component bumped.

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 version as a string.

Jump to

Keyboard shortcuts

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