version

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: LGPL-3.0 Imports: 7 Imported by: 218

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 = `` /* 140-byte string literal not displayed */
	// BinaryRegex for matching binary version strings in the form:
	// - 1.2-release-arch
	// - 1.2.3-release-arch
	// - 1.2.3.4-release-arch
	// - 1.2-alpha3-release-arch
	// - 1.2-alpha3.4-release-arch
	BinaryRegex = NumberRegex + `-(?P<release>[^-]+)-(?P<arch>[^-]+)`
)

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
	Release 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 a version in strict mode. The following version patterns are accepted:

1.2.3       (major, minor, patch)
1.2-tag3    (major, minor, patch, tag)
1.2.3.4     (major, minor, patch, build)
1.2-tag3.4  (major, minor, patch, build)

The ParseNonStrict function can be used instead to parse a wider range of version patterns (e.g. major only, major/minor etc.).

func ParseNonStrict

func ParseNonStrict(s string) (Number, error)

ParseNonStrict attempts to parse a version in non-strict mode. It supports the same patterns as Parse with the addition of some extra patterns that are not considered pure semantic version values.

The following version patterns are accepted:

1           (major)
1.2         (major, minor)
1.2.3       (major, minor, patch)
1.2-tag     (major, minor, tag)
1.2-tag3    (major, minor, patch, tag)
1.2.3.4     (major, minor, patch, build)
1.2-tag3.4  (major, minor, patch, build)

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

Jump to

Keyboard shortcuts

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