version

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 9

Documentation

Overview

Package version implements version handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	// KubeSemver is the regex for Kubernetes versions. It requires the "v" prefix.
	KubeSemver = regexp.MustCompile(`^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$`)
	// KubeSemverTolerant is the regex for Kubernetes versions with an optional "v" prefix.
	KubeSemverTolerant = regexp.MustCompile(`^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$`)
)

Functions

func Compare added in v0.99.99

func Compare(a, b semver.Version, options ...CompareOption) int

Compare 2 semver versions. Defaults to doing the standard semver comparison when no options are specified. The comparison logic can be modified by passing additional compare options. Example: using the WithBuildTags() option modifies the compare logic to also consider build tags when comparing versions.

func ParseMajorMinorPatch

func ParseMajorMinorPatch(version string) (semver.Version, error)

ParseMajorMinorPatch returns a semver.Version from the string provided by looking only at major.minor.patch and stripping everything else out. It requires the version to have a "v" prefix.

func ParseMajorMinorPatchTolerant

func ParseMajorMinorPatchTolerant(version string) (semver.Version, error)

ParseMajorMinorPatchTolerant returns a semver.Version from the string provided by looking only at major.minor.patch and stripping everything else out. It does not require the version to have a "v" prefix.

Types

type CompareOption added in v0.99.99

type CompareOption func(*comparer)

CompareOption is a configuration option for Compare.

func WithBuildTags added in v0.99.99

func WithBuildTags() CompareOption

WithBuildTags modifies the version comparison to also consider build tags when comparing versions. Performs a standard version compare between a and b. If the versions are equal, build identifiers will be used to compare further; precedence for two build identifiers is determined by comparing each dot-separated identifier from left to right until a difference is found as follows: - Identifiers consisting of only digits are compared numerically. - Numeric identifiers always have lower precedence than non-numeric identifiers. - Identifiers with letters or hyphens are compared only for equality, otherwise, 2 is returned given that it is not possible to identify if lower or greater (non-numeric identifiers could be random build identifiers).

-1 == a is less than b.
0 == a is equal to b.
1 == a is greater than b.
2 == v is different than o (it is not possible to identify if lower or greater).

func WithoutPreReleases added in v1.2.0

func WithoutPreReleases() CompareOption

WithoutPreReleases modifies the version comparison to not consider pre-releases when comparing versions.

Jump to

Keyboard shortcuts

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