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
- Variables
- func CompatibleWith(candidate, target string) bool
- func LooksValid(version string) bool
- type JSON
- type JSONNoFail
- type Range
- type RangeCondition
- type RangeJSON
- type RangeSpecifier
- type Version
- func (v *Version) Compare(other *Version) int
- func (v *Version) Equal(other *Version) bool
- func (v *Version) GreaterThan(other *Version) bool
- func (v *Version) GreaterThanOrEqual(other *Version) bool
- func (v *Version) InRange(r *Range) bool
- func (v *Version) IsAlpha() bool
- func (v *Version) IsQv() bool
- func (v *Version) LessThan(other *Version) bool
- func (v *Version) LessThanOrEqual(other *Version) bool
- func (v *Version) MarshalJSON() ([]byte, error)
- func (v *Version) Normal() string
- func (v *Version) NotEqual(other *Version) bool
- func (v *Version) Numify() float64
- func (v *Version) Raw() string
- func (v *Version) Stringify() string
- func (v *Version) UnmarshalJSON(data []byte) error
- func (v *Version) Version() []int64
Constants ¶
const ( LaxVersionRegex = internal.LaxVersionRegex StrictVersionRegex = internal.StrictVersionRegex )
Variables ¶
var (
ErrInvalidRangeCondition = errors.New("invalid range condition type")
)
Functions ¶
func CompatibleWith ¶
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 ¶
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 (*JSON) UnmarshalJSON ¶
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 ¶
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 ¶
ParseRange parses a string into a Range, in accordance with CPAN::Meta::Spec.
func (*Range) MarshalJSON ¶
func (*Range) UnmarshalJSON ¶
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 (*RangeJSON) UnmarshalJSON ¶
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 ¶
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 ¶
Parse parses a string into a Version. The string can be either a lax or strict versioning scheme, as defined in Version::Internals.
func (*Version) Compare ¶
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 ¶
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 ¶
GreaterThan checks whether a Version is newer than another.
func (*Version) GreaterThanOrEqual ¶
GreaterThanOrEqual checks whether a Version is newer or equivalent to another. Same as (GreaterThan || Equal).
func (*Version) IsAlpha ¶
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 ¶
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) LessThanOrEqual ¶
LessThanOrEqual checks whether a Version is older or equivalent to another. Same as (LessThan || Equal).
func (*Version) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. This allows for caching of the Version.
func (*Version) Normal ¶
Normal is a convenience function for normalizing a Version string. It returns it in standardized qv form, with at least three subversions.
func (*Version) Numify ¶
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) Stringify ¶
Stringify matches its Perl equivalent- functionally it acts the same as Raw, however if the Version is undefined, it returns "0".
func (*Version) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. This allows for extracting the Version from a cached Version.