version

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package version provides a version type and methods for working with versions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareASC

func CompareASC[T HasVersion](v, o T) int

CompareASC compares two versions (ASC) (less to greater). Use in slices.SortFunc.

Example usage:

slices.SortFunc(tags, version.CompareDESC[version.Version])

func CompareDESC

func CompareDESC[T HasVersion](v, o T) int

CompareDESC compares two versions (DESC) (greater to less). Use in slices.SortFunc.

Example usage:

slices.SortFunc(tags, version.CompareDESC[version.Version])

Types

type HasVersion

type HasVersion interface {
	Version() V
}

HasVersion interface.

type V

type V string

V version. Example: 1.0.0-asd+dd

[SEMANTIC VERSIONING] https://semver.org/

func (V) Compare

func (v V) Compare(o V) int

Compare with other version: @see https://semver.org/#spec-item-11

Precedence refers to how versions are compared to each other when ordered.

Precedence MUST be calculated by separating the version into major, minor, patch and pre-release identifiers in that order (Build metadata does not figure into precedence).

Precedence is determined by the first difference when comparing each of these identifiers from left to right as follows: Major, minor, and patch versions are always compared numerically.

Example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.

When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version:

Example: 1.0.0-alpha < 1.0.0.

Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows:

  • Identifiers consisting of only digits are compared numerically.
  • Identifiers with letters or hyphens are compared lexically in ASCII sort order. -Numeric identifiers always have lower precedence than non-numeric identifiers.
  • A larger set of pre-release fields has a higher precedence than a smaller set, if all the preceding identifiers are equal.

Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.

Return values are:

  • 0: equal;
  • 1: greater, then argument;
  • -1: les, then argument

func (V) Empty

func (v V) Empty() bool

Empty returns true if the version is empty.

func (V) Equal

func (v V) Equal(o V) bool

Equal returns true if the version is equal to the argument.

func (V) FormatString

func (v V) FormatString() string

FormatString returns the string value of the version in the specified format.

func (V) GitVersion

func (v V) GitVersion() string

GitVersion returns the git version (version, started from "v").

func (V) Invalid

func (v V) Invalid() bool

Invalid returns true if the version is invalid.

func (V) LessThen

func (v V) LessThen(o V) bool

LessThen returns true if the version is less then the argument.

func (V) NextMajor

func (v V) NextMajor() V

NextMajor returns the next major version.

func (V) NextMinor

func (v V) NextMinor() V

NextMinor returns the next minor version.

func (V) NextPatch

func (v V) NextPatch() V

NextPatch returns the next patch version.

func (V) Start

func (V) Start() V

Start returns the start version.

func (V) String

func (v V) String() string

String returns the string value of the version.

func (V) Version

func (v V) Version() V

Version returns the version for interface compatibility.

Jump to

Keyboard shortcuts

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