Documentation
¶
Overview ¶
Package version implements version handling.
Index ¶
- Variables
- func Compare(a, b semver.Version, options ...CompareOption) int
- func CompareWithBuildIdentifiers(a semver.Version, b semver.Version) int
- func ParseMajorMinorPatch(version string) (semver.Version, error)
- func ParseMajorMinorPatchTolerant(version string) (semver.Version, error)
- type CompareOption
Constants ¶
This section is empty.
Variables ¶
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 CompareWithBuildIdentifiers ¶ added in v0.4.1
func CompareWithBuildIdentifiers(a semver.Version, b semver.Version) int
CompareWithBuildIdentifiers compares two versions a and b. Perfoms a standard version compare between a and b. If the versions are equal, build identifiers will be used to compare further.
-1 == a is less than b.
0 == a is equal to b.
1 == a is greater than b.
Deprecated: Use Compare(a, b, WithBuildTags()) instead.
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.
-1 == a is less than b.
0 == a is equal to b.
1 == a is greater than b.