gover

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 7 Imported by: 0

README

gover

A simple yet powerful library for working with any kind of versions in Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMatch = errors.New("failed matching")
)
View Source
var RegexpSemver *regexp.Regexp = regexp.MustCompile(`^(?P<d1>\d+)\.(?P<d2>\d+)\.(?P<d3>\d+)(?:-(?P<s4>[^+]+))?(?:\+(?P<s5>.*))?$`)

A regex that matches the semantic versioning pattern. d.d.d(-s)(+s)

View Source
var RegexpSimple *regexp.Regexp = regexp.MustCompile(`^(?P<d1>\d+)(?:\.(?P<d2>\d+))?(?:\.(?P<d3>\d+))?$`)

A simple regexp that matches one, two or three digits separated by a dot. d(.d)(.d)

Functions

func Compare

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

func FindMaxGeneric added in v0.4.0

func FindMaxGeneric[T any](versions []T, getFunc func(x T) *Version, referenceVersion *Version, onlyWithoutStringValues bool) T

func Sort

func Sort(versions []*Version)

Types

type Version

type Version struct {
	Raw      string
	Segments []VersionSegment
}

Type that represents a version object.

var EmptyVersion *Version = &Version{}

An empty version, can be used to find the max version of a list.

func FindMax

func FindMax(versions []*Version, referenceVersion *Version, onlyWithoutStringValues bool) *Version

Gets the maximum version which complies to a given version of a list of versions.

func MustParseVersionFromRegex

func MustParseVersionFromRegex(versionString string, versionRegexp *regexp.Regexp) *Version

func ParseSimple

func ParseSimple(parts ...interface{}) *Version

Parses the given parts into a version.

func ParseVersionFromRegex

func ParseVersionFromRegex(versionString string, versionRegexp *regexp.Regexp) (*Version, error)

Parses the given version string with the regexp into the version object.

func (*Version) CompareTo

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

func (*Version) CoreVersion added in v0.5.1

func (v *Version) CoreVersion() string

CoreVersion Converts the version to a core SemVer string in the form major.minor.path

func (*Version) Equals added in v0.3.0

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

func (*Version) GreaterThan added in v0.1.3

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

func (*Version) LessThan added in v0.1.3

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

func (*Version) Major

func (v *Version) Major() int

func (*Version) Minor

func (v *Version) Minor() int

func (*Version) Patch

func (v *Version) Patch() int

func (*Version) String

func (v *Version) String() string

Converts the version to a readable string.

type VersionSegment

type VersionSegment struct {
	Number       int
	Text         string
	IsText       bool
	IsNotDefined bool
}

A segment of the version, can either be a number or a text.

func (*VersionSegment) String

func (v *VersionSegment) String() string

Converts the version segment to a readable string.

Jump to

Keyboard shortcuts

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