version

package module
v0.0.0-...-63bfda2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 3 Imported by: 1

README

Go Version

A simple library for parsing and comparing versions according to Semantic Versioning 2.0.0.

License

See LICENSE.md

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidVersion = Error{Message: "invalid version %q"}
)

Version error.

Functions

This section is empty.

Types

type Constraint

type Constraint struct {
	Gt  *Version // Greater than...
	Gte *Version // Greater than or equal to...
	Lt  *Version // Less than...
	Lte *Version // Less than or equal to...
}

Constraint enables matching a version based on lower and upper bounds.

type Error

type Error struct {
	Message string
	Version string
}

Error represents a version error.

func (Error) Error

func (e Error) Error() string

Error retrieves the message of a REST API error.

func (Error) Is

func (e Error) Is(target error) bool

Is determines whether the Error is an instance of the target. https://pkg.go.dev/errors#Is

This implementation does not compare versions.

type List

type List []*Version

List is a slice of versions that implements sort.Interface.

func (List) Len

func (list List) Len() int

func (List) Less

func (list List) Less(i, j int) bool

func (List) Match

func (list List) Match(c *Constraint) List

Match tests versions against a constraint and returns a new List of matching versions only.

func (List) Swap

func (list List) Swap(i, j int)

type Version

type Version struct {
	Major     int    // Major version number.
	Minor     int    // Minor version number.
	Patch     int    // Patch version number.
	Extension string // Version extension, such as pre-release number or build metdata.

	Text string // Original version string, if this version was created via the Parse function.
}

Version is a structured representation of a version number.

func MustParse

func MustParse(str string) *Version

func Parse

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

func (*Version) Compare

func (a *Version) Compare(b *Version) int

Compare this version (a) with another version (b). This function returns -1 if a is less than b, 1 if a is greater than b, or 0 if a is equal to b.

Extensions such as pre-release version or build metadata are ignored when comparing versions.

func (*Version) Equal

func (a *Version) Equal(b *Version) bool

Equal checks for equality between two versions.

Extensions such as pre-release version or build metadata are ignored when comparing versions.

func (*Version) Less

func (a *Version) Less(b *Version) bool

Less performs a simple comparison of this version (a) with another version (b). This function returns true if a is less than b, or false otherwise.

Extensions such as pre-release version or build metadata are ignored when comparing versions.

func (*Version) Match

func (v *Version) Match(c *Constraint) bool

Match tests the version against a constraint. Gt and Lt take precedence over Gte and Lte.

func (*Version) SemanticString

func (v *Version) SemanticString() string

SemanticString returns a version string conforming to the standard described in Semantic Versioning 2.0.0.

See https://semver.org/#is-v123-a-semantic-version

func (*Version) String

func (v *Version) String() string

Jump to

Keyboard shortcuts

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