version

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package version is a Go implementation of Perl's version.pm. It's written for the purpose of working with Perl packages in the context of a larger, multi-language monorepo. It's written to be a bug-for-bug compatible implementation of Perl's Version.pm.

Index

Constants

View Source
const (
	LaxVersionRegex    = internal.LaxVersionRegex
	StrictVersionRegex = internal.StrictVersionRegex
)

Variables

View Source
var (
	ErrInvalidRangeCondition = errors.New("invalid range condition type")
)

Functions

func CompatibleWith

func CompatibleWith(candidate, target string) bool

CompatibleWith checks if candidate is compatible with target. Panics if it can't parse either of the two; this is meant for already-validated versions. If you need to check, use the respective Version method Version.GreaterThanOrEqual.

func LooksValid

func LooksValid(version string) bool

LooksValid returns true if the Version looks valid. It can sometimes return false positives in edge cases that can't be easily checked, but if it says it's not valid, it's not valid.

Types

type JSON

type JSON struct {
	Version
}

JSON is a wrapper around Version that implements json.Marshaler and json.Unmarshaler as a string.

func (*JSON) MarshalJSON

func (j *JSON) MarshalJSON() ([]byte, error)

func (*JSON) String

func (j *JSON) String() string

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(b []byte) error

type JSONNoFail

type JSONNoFail struct{ Version }

func (*JSONNoFail) MarshalJSON

func (j *JSONNoFail) MarshalJSON() ([]byte, error)

func (*JSONNoFail) String

func (j *JSONNoFail) String() string

func (*JSONNoFail) UnmarshalJSON

func (j *JSONNoFail) UnmarshalJSON(b []byte) error

type Range

type Range struct {
	// contains filtered or unexported fields
}

Range is a set of conditions that must all be true for a version to be considered to be in the range. The conditions are ANDed together.

func MustParseRange

func MustParseRange(s string) *Range

MustParseRange is like ParseRange, but panics if there's an error

func NewRange

func NewRange(conditions []RangeSpecifier) (*Range, error)

func NewRangeNoFail

func NewRangeNoFail(conditions []RangeSpecifier) *Range

NewRangeNoFail is like NewRange, but panics if there's an error

func ParseRange

func ParseRange(s string) (*Range, error)

ParseRange parses a string into a Range, in accordance with CPAN::Meta::Spec.

func (*Range) Contains

func (r *Range) Contains(v *Version) bool

func (*Range) MarshalJSON

func (r *Range) MarshalJSON() ([]byte, error)

func (*Range) String

func (r *Range) String() string

func (*Range) URLString

func (r *Range) URLString() string

func (*Range) UnmarshalJSON

func (r *Range) UnmarshalJSON(b []byte) error

type RangeCondition

type RangeCondition int32
const (
	RangeConditionGreaterThan RangeCondition
	RangeConditionGreaterThanOrEqual
	RangeConditionLessThan
	RangeConditionLessThanOrEqual
	RangeConditionNotEqual
	RangeConditionEqual
)

func (*RangeCondition) MarshalJSON

func (c *RangeCondition) MarshalJSON() ([]byte, error)

func (*RangeCondition) String

func (c *RangeCondition) String() string

func (*RangeCondition) URLString

func (c *RangeCondition) URLString() string

func (*RangeCondition) UnmarshalJSON

func (c *RangeCondition) UnmarshalJSON(b []byte) error

type RangeJSON

type RangeJSON struct {
	Range
}

RangeJSON is a wrapper around Range that implements json.Marshaler and json.Unmarshaler as a string.

func (*RangeJSON) MarshalJSON

func (rs *RangeJSON) MarshalJSON() ([]byte, error)

func (*RangeJSON) UnmarshalJSON

func (rs *RangeJSON) UnmarshalJSON(b []byte) error

type RangeSpecifier

type RangeSpecifier struct {
	Condition RangeCondition `json:"range_type"`
	Version   Version        `json:"version"`
}

func (*RangeSpecifier) String

func (rc *RangeSpecifier) String() string

func (*RangeSpecifier) URLString

func (rc *RangeSpecifier) URLString() string

type Version

type Version struct {
	// contains filtered or unexported fields
}

Version is a direct, mapping of Perl's Version::Internal, methods and all. It's meant to be opaque, as the internal representation might change if the need arises.

func MustParse

func MustParse(version string) Version

MustParse is for parsing a Version string that must be valid. It panics if it can't parse the string. You probably want Parse(), unless you're dealing with an internal cache.

func Parse

func Parse(version string) (Version, error)

Parse parses a string into a Version. The string can be either a lax or strict versioning scheme, as defined in Version::Internals.

func Undef

func Undef() Version

Undef returns a new, undefined Version.

func (*Version) Compare

func (v *Version) Compare(other *Version) int

Compare compares two versions. It returns -1 if the receiver is older, 0 if they're equivalent, and 1 if the receiver is newer.

func (*Version) Equal

func (v *Version) Equal(other *Version) bool

Equal checks whether two versions are the same. This doesn't strictly mean they're identical, it means, for example, "v5.34" counts as the same as "v5.34.0" *or* "v5.34.1".

func (*Version) GreaterThan

func (v *Version) GreaterThan(other *Version) bool

GreaterThan checks whether a Version is newer than another.

func (*Version) GreaterThanOrEqual

func (v *Version) GreaterThanOrEqual(other *Version) bool

GreaterThanOrEqual checks whether a Version is newer or equivalent to another. Same as (GreaterThan || Equal).

func (*Version) InRange

func (v *Version) InRange(r *Range) bool

func (*Version) IsAlpha

func (v *Version) IsAlpha() bool

IsAlpha checks whether a Version is an alpha Version. This is implied by the presence of an underscore in the Version. For example, "1.2_3" is an alpha Version (equating to "v1.203.0", but that's due to Perl's bizarre Version semantics).

func (*Version) IsQv

func (v *Version) IsQv() bool

IsQv checks whether a Version is a qv Version. This is indicated by a 'v' at the beginning of the Version. For example, "v1.2.3" is a qv Version, while "1.2.3" is not. The versions are not equal either- "1.2.3" is represented as "v1.200.300", and "v1.2.3" is still just "v1.2.3".

func (*Version) LessThan

func (v *Version) LessThan(other *Version) bool

LessThan checks whether a Version is older than another.

func (*Version) LessThanOrEqual

func (v *Version) LessThanOrEqual(other *Version) bool

LessThanOrEqual checks whether a Version is older or equivalent to another. Same as (LessThan || Equal).

func (*Version) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface. This allows for caching of the Version.

func (*Version) Normal

func (v *Version) Normal() string

Normal is a convenience function for normalizing a Version string. It returns it in standardized qv form, with at least three subversions.

func (*Version) NotEqual

func (v *Version) NotEqual(other *Version) bool

NotEqual checks whether two versions are not the same. Same as !(Equal).

func (*Version) Numify

func (v *Version) Numify() float64

Numify returns the numeric Version of a Version string. For example, "v1.2.3" would return 1.002003. This is useful for quick comparisons, and embedding in maps, though if you have a Version with many subversions, it's probably better to use the relevant comparison methods (which are probably faster regardless).

func (*Version) Raw

func (v *Version) Raw() string

Raw returns the original representation of the Version.

func (*Version) Stringify

func (v *Version) Stringify() string

Stringify matches its Perl equivalent- functionally it acts the same as Raw, however if the Version is undefined, it returns "0".

func (*Version) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface. This allows for extracting the Version from a cached Version.

func (*Version) Version

func (v *Version) Version() []int64

Version returns the Version as a slice of integers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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