version

package module
Version: v0.0.0-...-2015802 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: LGPL-3.0 Imports: 6 Imported by: 273

README

Version GoDoc

version is a go package for intelligent version comparisons.

Documentation

Overview

Package version implements version parsing.

Index

Constants

View Source
const (
	// NumberRegex for matching version strings in the forms:
	// - 1.2
	// - 1.2.3
	// - 1.2.3.4
	// - 1.2-alpha3
	// - 1.2-alpha3.4
	NumberRegex = `(\d{1,9})\.(\d{1,9})(?:\.|-([a-z]+))(\d{1,9})(\.\d{1,9})?`
	// BinaryRegex for matching binary version strings in the form:
	// - 1.2-series-arch
	// - 1.2.3-series-arch
	// - 1.2.3.4-series-arch
	// - 1.2-alpha3-series-arch
	// - 1.2-alpha3.4-series-arch
	BinaryRegex = NumberRegex + `-([^-]+)-([^-]+)`
)

Variables

View Source
var Zero = Number{}

Zero is occasionally convenient and readable. Please don't change its value.

Functions

func ParseMajorMinor

func ParseMajorMinor(vers string) (int, int, error)

ParseMajorMinor takes an argument of the form "major.minor" and returns ints major and minor.

Types

type Binary

type Binary struct {
	Number
	Series string
	Arch   string
}

Binary specifies a binary version of juju.v

func MustParseBinary

func MustParseBinary(s string) Binary

MustParseBinary parses a binary version and panics if it does not parse correctly.

func ParseBinary

func ParseBinary(s string) (Binary, error)

ParseBinary parses a binary version of the form "1.2.3-series-arch".

func (Binary) GetBSON

func (b Binary) GetBSON() (interface{}, error)

GetBSON implements bson.Getter.

func (Binary) MarshalJSON

func (b Binary) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Binary) MarshalYAML

func (b Binary) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.v2.Marshaller interface.

func (*Binary) SetBSON

func (b *Binary) SetBSON(raw bson.Raw) error

SetBSON implements bson.Setter.

func (Binary) String

func (b Binary) String() string

String returns the string representation of the binary version.

func (*Binary) UnmarshalJSON

func (b *Binary) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Binary) UnmarshalYAML

func (b *Binary) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaller interface.

type Number

type Number struct {
	Major int
	Minor int
	Tag   string
	Patch int
	Build int
}

Number represents a version number.

func MustParse

func MustParse(s string) Number

MustParse parses a version and panics if it does not parse correctly.

func Parse

func Parse(s string) (Number, error)

Parse parses the version, which is of the form 1.2.3 giving the major, minor and release versions respectively.

func (Number) Compare

func (n Number) Compare(other Number) int

Compare returns -1, 0 or 1 depending on whether n is less than, equal to or greater than other. The comparison compares Major, then Minor, then Patch, then Build, using the first difference as

func (Number) GetBSON

func (n Number) GetBSON() (interface{}, error)

GetBSON implements bson.Getter.

func (Number) MarshalJSON

func (n Number) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Number) MarshalYAML

func (n Number) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.v2.Marshaller interface

func (*Number) SetBSON

func (n *Number) SetBSON(raw bson.Raw) error

SetBSON implements bson.Setter.

func (Number) String

func (n Number) String() string

String returns the string representation of this Number.

func (Number) ToPatch

func (n Number) ToPatch() Number

ToPatch returns back a semver Number (Major.Minor.Tag.Patch), without a build attached to the Number. In some scenarios it's prefable to not have the build number to identity a version and instead use a less qualified Number. Being less specific about exactness allows us to be more flexible about compatible with other versions.

func (*Number) UnmarshalJSON

func (n *Number) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Number) UnmarshalYAML

func (n *Number) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaller interface

Source Files

Jump to

Keyboard shortcuts

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