Documentation
¶
Overview ¶
Package semantic provides version parsing and comparison for various ecosystems, matching the native versioning rules of each ecosystem.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidVersion = errors.New("invalid version")
ErrInvalidVersion is returned for malformed version strings.
var ErrNotSameEcosystem = errors.New("version is not of the same ecosystem")
ErrNotSameEcosystem is returned when comparing two versions of different ecosystems.
var ErrUnsupportedEcosystem = errors.New("unsupported ecosystem")
ErrUnsupportedEcosystem is returned for unsupported ecosystems.
Functions ¶
This section is empty.
Types ¶
type AlpineVersion ¶ added in v0.4.5
type AlpineVersion struct {
// contains filtered or unexported fields
}
AlpineVersion represents a version of an Alpine package.
Currently, the APK version specification is as follows: *number{.number}...{letter}{\_suffix{number}}...{~hash}{-r#}*
Each *number* component is a sequence of digits (0-9).
The *letter* portion can follow only after end of all the numeric version components. The *letter* is a single lower case letter (a-z). This can follow one or more *\_suffix{number}* components. The list of valid suffixes (and their sorting order) is: *alpha*, *beta*, *pre*, *rc*, <no suffix>, *cvs*, *svn*, *git*, *hg*, *p*
This can be follows with an optional *{~hash}* to indicate a commit hash from where it was built. This can be any length string of lower case hexadecimal digits (0-9a-f).
Finally, an optional package build component *-r{number}* can follow.
Also see https://github.com/alpinelinux/apk-tools/blob/master/doc/apk-package.5.scd#package-info-metadata
func ParseAlpineVersion ¶ added in v0.4.5
func ParseAlpineVersion(str string) (AlpineVersion, error)
ParseAlpineVersion parses the given string as an Alpine version.
func (AlpineVersion) Compare ¶ added in v0.4.5
func (v AlpineVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (AlpineVersion) CompareStr ¶ added in v0.4.5
func (v AlpineVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type CRANVersion ¶ added in v0.4.5
type CRANVersion struct {
// contains filtered or unexported fields
}
CRANVersion is the representation of a version of a package that is held in the CRAN ecosystem (https://cran.r-project.org/).
A version is a sequence of at least two non-negative integers separated by either a period or a dash.
See https://astrostatistics.psu.edu/su07/R/html/base/html/package_version.html
func ParseCRANVersion ¶ added in v0.4.5
func ParseCRANVersion(str string) (CRANVersion, error)
ParseCRANVersion parses the given string as a CRAN version.
func (CRANVersion) Compare ¶ added in v0.4.5
func (v CRANVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (CRANVersion) CompareStr ¶ added in v0.4.5
func (v CRANVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type DebianVersion ¶ added in v0.4.5
type DebianVersion struct {
// contains filtered or unexported fields
}
DebianVersion represents a version of a Debian package.
See https://man7.org/linux/man-pages/man7/deb-version.7.html
func ParseDebianVersion ¶ added in v0.4.5
func ParseDebianVersion(str string) (DebianVersion, error)
ParseDebianVersion parses the given string as a Debian version.
func (DebianVersion) Compare ¶ added in v0.4.5
func (v DebianVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (DebianVersion) CompareStr ¶ added in v0.4.5
func (v DebianVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type HackageVersion ¶ added in v0.4.5
type HackageVersion struct {
// contains filtered or unexported fields
}
HackageVersion is the representation of a version of a package that is held in the Hackage ecosystem.
func ParseHackageVersion ¶ added in v0.4.5
func ParseHackageVersion(str string) (HackageVersion, error)
ParseHackageVersion parses the given string as a Hackage version.
func (HackageVersion) Compare ¶ added in v0.4.5
func (v HackageVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (HackageVersion) CompareStr ¶ added in v0.4.5
func (v HackageVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type MavenVersion ¶ added in v0.4.5
type MavenVersion struct {
// contains filtered or unexported fields
}
MavenVersion is the representation of a version of a package that is held in the Maven ecosystem.
See https://maven.apache.org/pom.html#version-order-specification
func ParseMavenVersion ¶ added in v0.4.5
func ParseMavenVersion(str string) MavenVersion
ParseMavenVersion parses the given string as a Maven version.
func (MavenVersion) Compare ¶ added in v0.4.5
func (mv MavenVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (MavenVersion) CompareStr ¶ added in v0.4.5
func (mv MavenVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type NuGetVersion ¶ added in v0.4.5
type NuGetVersion struct {
// contains filtered or unexported fields
}
NuGetVersion is the representation of a version of a package that is held in the NuGet ecosystem.
See https://learn.microsoft.com/en-us/nuget/concepts/package-versioning
func ParseNuGetVersion ¶ added in v0.4.5
func ParseNuGetVersion(str string) NuGetVersion
ParseNuGetVersion parses the given string as a NuGet version.
func (NuGetVersion) Compare ¶ added in v0.4.5
func (v NuGetVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (NuGetVersion) CompareStr ¶ added in v0.4.5
func (v NuGetVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type PackagistVersion ¶ added in v0.4.5
type PackagistVersion struct {
// contains filtered or unexported fields
}
PackagistVersion is the representation of a version of a package that is held in the Packagist ecosystem.
func ParsePackagistVersion ¶ added in v0.4.5
func ParsePackagistVersion(str string) PackagistVersion
ParsePackagistVersion parses the given string as a Packagist version.
func (PackagistVersion) Compare ¶ added in v0.4.5
func (v PackagistVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (PackagistVersion) CompareStr ¶ added in v0.4.5
func (v PackagistVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type PubVersion ¶ added in v0.4.5
type PubVersion struct {
// contains filtered or unexported fields
}
PubVersion is the representation of a version of a package that is held in the Pub ecosystem.
See https://pub.dev/packages/pub_semver
func ParsePubVersion ¶ added in v0.4.5
func ParsePubVersion(str string) PubVersion
ParsePubVersion parses the given string as a Pub version.
func (PubVersion) Compare ¶ added in v0.4.5
func (v PubVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (PubVersion) CompareStr ¶ added in v0.4.5
func (v PubVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type PyPIVersion ¶ added in v0.4.5
type PyPIVersion struct {
// contains filtered or unexported fields
}
PyPIVersion is the representation of a version of a package that is held in the PyPI ecosystem.
See https://peps.python.org/pep-0440/
func ParsePyPIVersion ¶ added in v0.4.5
func ParsePyPIVersion(str string) (PyPIVersion, error)
ParsePyPIVersion parses the given string as a PyPI version.
func (PyPIVersion) Compare ¶ added in v0.4.5
func (pv PyPIVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (PyPIVersion) CompareStr ¶ added in v0.4.5
func (pv PyPIVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type RedHatVersion ¶ added in v0.4.5
type RedHatVersion struct {
// contains filtered or unexported fields
}
RedHatVersion is the representation of a version of a package that is held in the Red Hat ecosystem.
See https://docs.fedoraproject.org/en-US/packaging-guidelines/Versioning/
func ParseRedHatVersion ¶ added in v0.4.5
func ParseRedHatVersion(str string) RedHatVersion
ParseRedHatVersion parses a Red Hat version into a RedHatVersion struct.
A Red Hat version contains the following components: - epoch, represented as "e" - version, represented as "v" - release, represented as "r"
When all components are present, the version is represented as "e:v-r", though only the version is actually required.
func (RedHatVersion) Compare ¶ added in v0.4.5
func (v RedHatVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (RedHatVersion) CompareStr ¶ added in v0.4.5
func (v RedHatVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type RubyGemsVersion ¶ added in v0.4.5
type RubyGemsVersion struct {
// contains filtered or unexported fields
}
RubyGemsVersion is the representation of a version of a package that is held in the RubyGems ecosystem.
func ParseRubyGemsVersion ¶ added in v0.4.5
func ParseRubyGemsVersion(str string) RubyGemsVersion
ParseRubyGemsVersion parses the given string as a RubyGems version.
func (RubyGemsVersion) Compare ¶ added in v0.4.5
func (v RubyGemsVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (RubyGemsVersion) CompareStr ¶ added in v0.4.5
func (v RubyGemsVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type SemverVersion ¶ added in v0.4.5
type SemverVersion struct {
// contains filtered or unexported fields
}
SemverVersion is the representation of a Semver 2.0.0 version.
See https://semver.org/spec/v2.0.0.html
func ParseSemverVersion ¶ added in v0.4.5
func ParseSemverVersion(str string) SemverVersion
ParseSemverVersion parses the given string as a Semver version.
func (SemverVersion) Compare ¶ added in v0.4.5
func (v SemverVersion) Compare(w Version) (int, error)
Compare compares the given version to the receiver.
func (SemverVersion) CompareStr ¶ added in v0.4.5
func (v SemverVersion) CompareStr(str string) (int, error)
CompareStr compares the given string to the receiver.
type Version ¶
type Version interface {
// Compare returns an integer representing the sort order of the given Version
// relative to the subject Version.
//
// The result will be 0 if v == w, -1 if v < w, or +1 if v > w.
//
// ErrNotSameEcosystem is returned if the given Version is not of the same
// ecosystem as the subject Version.
Compare(v Version) (int, error)
// CompareStr returns an integer representing the sort order of the given string
// when parsed as the concrete Version relative to the subject Version.
//
// The result will be 0 if v == w, -1 if v < w, or +1 if v > w.
//
// An error is returned if the given string is not a valid Version, with "valid"
// being dependent on the underlying ecosystem of the concrete Version.
CompareStr(str string) (int, error)
}
Version provides an interface for sortable version strings.