Documentation
¶
Overview ¶
Package semver contains methods of working with semantic versions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnsupportedVersionFormat = errors.New("unsupported version format")
)
Functions ¶
func CompareVersions ¶
CompareVersions compares two compatible [Version]s. Returns a negative number when a < b, a positive number when a > b and zero when a == b. Useful to use as a sort func.
func LatestOpinionatedVersionString ¶
LatestOpinionatedVersionString returns the latest compatible version and whether or not a compatible version was found. If there is a new version on the same major as the current, it is preferred. If the current version is the newest version of the major, the latest version is returned. This allows more graceful handling of version tracks for things like databases where multiple majors are supported concurrently.
func PackInt64 ¶
PackInt64 packs a Version into a lossy format which fits into a 64-bit int. The resulting int is sortable when compared to compatible versions. That is, a version of a higher major, higher minor, higher patch and so on will be a higher value than a lower version. Useful for creating a value which is then used to diff two versions of the same image. The resulting diff is sortable among with calculated values. Might fall apart if there are many parts, but most of the time, there are only three or four version parts. Note that it is valid to pass a nil Version, which will be treated as a unknown version.
Types ¶
type Version ¶
type Version struct { Release []int Suffix string Prerelease string // contains filtered or unexported fields }
func ParseVersion ¶
ParseVersion parses a Version. Returns ErrUnsupportedVersionFormat if the version is not parsable.
func (*Version) Compare ¶
Compare compares two versions. Returns a negative number when v < other, a positive number when v > other and zero when v == other.
func (*Version) Diff ¶
Diff returns the type of bump that differs v to other. Returns an empty string in cases where a bump could not be found.
func (*Version) IsCompatible ¶
IsCompatible returns true if v can be compared to other.