semver

package
v0.0.0-...-614ca16 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Semantic Versions http://org

Index

Examples

Constants

View Source
const (
	BumpMajor = Bump("major")
	BumpMinor = Bump("minor")
	BumpPatch = Bump("patch")
	BumpNone  = Bump("none")
	Unknown   = Bump("unknown")
)

Variables

This section is empty.

Functions

func Sort

func Sort(versions []Version)

Sort sorts the given slice of Version

func StringOrDefault

func StringOrDefault(v *Version) string

Types

type Bump

type Bump string

type PreRelease

type PreRelease string

func (PreRelease) Slice

func (p PreRelease) Slice() []string

type Range

type Range func(Version) bool

Range represents a range of versions. A Range can be used to check if a Version satisfies it:

range, err := semver.ParseRange(">1.0.0 <2.0.0")
range(semver.MustParse("1.1.1") // returns true

func MustParseRange

func MustParseRange(s string) Range

MustParseRange is like ParseRange but panics if the range cannot be parsed.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses a range and returns a Range. If the range could not be parsed an error is returned.

Valid ranges are:

  • "<1.0.0"
  • "<=1.0.0"
  • ">1.0.0"
  • ">=1.0.0"
  • "1.0.0", "=1.0.0", "==1.0.0"
  • "!1.0.0", "!=1.0.0"

A Range can consist of multiple ranges separated by space: Ranges can be linked by logical AND:

  • ">1.0.0 <2.0.0" would match between both ranges, so "1.1.1" and "1.8.7" but not "1.0.0" or "2.0.0"
  • ">1.0.0 <3.0.0 !2.0.3-beta.2" would match every version between 1.0.0 and 3.0.0 except 2.0.3-beta.2

Ranges can also be linked by logical OR:

  • "<2.0.0 || >=3.0.0" would match "1.x.x" and "3.x.x" but not "2.x.x"

AND has a higher precedence than OR. It's not possible to use brackets.

Ranges can be combined by both AND and OR

  • `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1`

func (Range) AND

func (rf Range) AND(f Range) Range

AND combines the existing Range with another Range using logical AND.

func (Range) OR

func (rf Range) OR(f Range) Range

OR combines the existing Range with another Range using logical OR.

type Version

type Version struct {
	Major      int64
	Minor      int64
	Patch      int64
	PreRelease PreRelease
	Metadata   string
}

func Must

func Must(v Version, err error) Version

Must is a helper for wrapping NewVersion and will panic if err is not nil.

func MustParse

func MustParse(version string) Version

func New

func New(version string) Version

func NewVersion

func NewVersion(version string) (Version, error)

func Parse

func Parse(version string) (Version, error)

func (Version) Bump

func (v Version) Bump(bump string) (Version, error)

func (Version) BumpMajor

func (v Version) BumpMajor() Version

BumpMajor returns a copy of the version after it increments the Major field by 1 and resets all other fields to their default values

func (Version) BumpMinor

func (v Version) BumpMinor() Version

BumpMinor returns a copy of the version after it increments the Minor field by 1 and resets all other fields to their default values

func (Version) BumpPatch

func (v Version) BumpPatch() Version

BumpPatch returns a copy of the version after it increments the Patch field by 1 and resets all other fields to their default values

func (Version) Compare

func (v Version) Compare(versionB Version) int

Compare tests if v is less than, equal to, or greater than versionB, returning -1, 0, or +1 respectively.

func (Version) Empty

func (v Version) Empty() bool

func (Version) Equal

func (v Version) Equal(versionB Version) bool

Equal tests if v is equal to versionB.

func (*Version) EqualSafe

func (v *Version) EqualSafe(versionB Version) bool

Equal tests if v points to a version which is equal to versionB.

func (Version) LessThan

func (v Version) LessThan(versionB Version) bool

LessThan tests if v is less than versionB.

Example
vA := New("1.2.3")
vB := New("3.2.1")

fmt.Printf("%s < %s == %t\n", vA, vB, vA.LessThan(vB))
Output:

1.2.3 < 3.2.1 == true

func (Version) MarshalJSON

func (v Version) MarshalJSON() ([]byte, error)

func (Version) MarshalYAML

func (v Version) MarshalYAML() (interface{}, error)

func (*Version) Set

func (v *Version) Set(version string) error

Set parses and updates v from the given version string. Implements flag.Value

func (Version) Slice

func (v Version) Slice() []int64

Slice converts the comparable parts of the semver into a slice of integers.

func (Version) String

func (v Version) String() string

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(data []byte) error

func (*Version) UnmarshalYAML

func (v *Version) UnmarshalYAML(unmarshal func(interface{}) error) error

type Versions

type Versions []Version

func (Versions) Len

func (s Versions) Len() int

func (Versions) Less

func (s Versions) Less(i, j int) bool

func (Versions) Swap

func (s Versions) Swap(i, j int)

Jump to

Keyboard shortcuts

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