version

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package version implements semantic version according to semver.org 2.0.0 specs. Beside regular version parsing, the package can also process and compare version ranges

v, err := version.New("1.2.3-alpha")
v1, err := version.New("^1.2.0")

// version formats accepted
v.Equal(v1) // true
v.Equal("v2.0.0") // false
v.Equal("2.0.0") // false
v.Equal("1.2.3-alpha+sh1.123") // false
v.Equal("1.2.3+sh1.123") // false
v.Equal("1.2.3-beta") // false
// Range inclusion comparison
v.Equal("~1.2.5") // true
v.Equal("^1.0") // true
v.Equal("*") // true

// version comparison methods
v.Equal("1.2.3-alpha") // true
v.LessThan("1.2.3-beta") // true
v.LessEqThan("1.3.0") // true
v.GreaterThan("0.0.1") // true
v.GreaterEqThan("2.0.0") // true

// Release methods
v, _ := version.New("1.2.3-alpha+tag")
v.ReleaseDev("beta") // 1.2.3-beta
v.ReleasePatch() // 1.2.4
v.ReleaseMinor() // 1.3.0
v.ReleaseMahor() // 2.0.0

Package version implements semantic version according to semver.org 2.0.0 specs

More details about semver you can see at http://semver.org/ The package can also process and compare version ranges (^1.2.3, ~1.2.3, *)

Index

Constants

This section is empty.

Variables

View Source
var (

	// AppVersion represents the application version and is overwritten at compile time
	AppVersion = "1.0.0"
)

Functions

This section is empty.

Types

type Version

type Version struct {
	Major      uint64
	Minor      uint64
	Patch      uint64
	PreRelease string
	Meta       string
	// contains filtered or unexported fields
}

Version contains a breakdown of a semver version number

func New

func New(val string) (*Version, error)

New parses a string into a Version object

func (*Version) Equal

func (v *Version) Equal(val interface{}) bool

Equal accepts a version string or Version object and compares version equality. Equal will also return true if one of the versions have a range defined and contains the other one Eg:

1.2.3 eq ~1.2
1.9 eq ^1.2
1.2 eq *

func (*Version) GreaterEqThan

func (v *Version) GreaterEqThan(val interface{}) bool

GreaterEqThan accepts a version string or Version object and tests if current version is greater or equal to the given test value

func (*Version) GreaterThan

func (v *Version) GreaterThan(val interface{}) bool

GreaterThan accepts a version string or Version object and tests if current version is greater than given test value

func (*Version) LessEqThan

func (v *Version) LessEqThan(val interface{}) bool

LessEqThan accepts a version string or Version object and tests if current version is less or equal to the given test value

func (*Version) LessThan

func (v *Version) LessThan(val interface{}) bool

LessThan accepts a version string or Version object and tests if current version is less than given test value

func (Version) MarshalJSON

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

MarshalJSON implements JSON Encoder interface

func (*Version) MarshalYAML

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

MarshalYAML implements YAML Encoder interface

func (*Version) ReleaseDev

func (v *Version) ReleaseDev(stage string)

ReleaseDev will change the PreRelease tag and clear any meta data after it Eg. 1.3.4-alpha+sha.123 ->beta-> 1.3.4-beta

func (*Version) ReleaseMajor

func (v *Version) ReleaseMajor()

ReleaseMajor will increment major version and clear everything after it Eg. 1.3.4-alpha+sha.123 -> 2.0.0

func (*Version) ReleaseMinor

func (v *Version) ReleaseMinor()

ReleaseMinor will increment minor version and clear everything after it Eg. 1.3.4-alpha+sha.123 -> 1.4.0

func (*Version) ReleasePatch

func (v *Version) ReleasePatch()

ReleasePatch will increment patch version and clear everything after it Eg. 1.3.4-alpha+sha.123 -> 1.3.5

func (Version) String

func (v Version) String() string

Return a string representation of the version

func (*Version) UnmarshalJSON

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

UnmarshalJSON implements JSON Decoder interface

func (*Version) UnmarshalYAML

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

UnmarshalYAML implements YAML Decoder interface

Jump to

Keyboard shortcuts

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