version

package module
v0.0.0-...-54dac30 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: Apache-2.0 Imports: 9 Imported by: 2

README

version

Parse and manipulate CockroachDB version strings.

Build Status Go Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MajorVersion

type MajorVersion struct {
	Year, Ordinal int
}

A MajorVersion represents a CockroachDB major version or release series, ie "v25.1".

func MustParseMajorVersion

func MustParseMajorVersion(versionStr string) MajorVersion

MustParseMajorVersion is like ParseMajorVersion but panics on any error. Recommended as an initializer for global values.

func ParseMajorVersion

func ParseMajorVersion(versionStr string) (MajorVersion, error)

ParseMajorVersion constructs a MajorVersion from a string.

func (MajorVersion) AtLeast

func (m MajorVersion) AtLeast(o MajorVersion) bool

func (MajorVersion) Compare

func (m MajorVersion) Compare(o MajorVersion) int

Compare returns -1, 0, or +1 indicating the relative ordering of major versions.

func (MajorVersion) Empty

func (m MajorVersion) Empty() bool

Empty returns true if the MajorVersion is the zero value.

func (MajorVersion) Equals

func (m MajorVersion) Equals(o MajorVersion) bool

func (MajorVersion) LessThan

func (m MajorVersion) LessThan(o MajorVersion) bool

func (MajorVersion) SafeFormat

func (m MajorVersion) SafeFormat(p redact.SafePrinter, _ rune)

SafeFormat implements redact.SafeFormatter.

func (MajorVersion) String

func (m MajorVersion) String() string

String returns the original string passed to ParseMajorVersion.

type NullVersion

type NullVersion struct {
	Valid   bool
	Version Version
}

Represents a NULLable version when stored in the database. The zero value of NullVersion serializes as database NULL (and vice-versa).

func NewNullVersion

func NewNullVersion(v Version) NullVersion

func (*NullVersion) Scan

func (n *NullVersion) Scan(value interface{}) error

Scan implements sql.Scanner, and is used when deserializing a NullVersion from the db.

func (*NullVersion) UnmarshalJSON

func (n *NullVersion) UnmarshalJSON(data []byte) error

We must implement json.Unmarshaler, because the invalid NullVersion stores an empty string in the version field, and we don't want to make Version unmarshal successfully from empty string (it should and does maintain the same behavior as Parse).

func (NullVersion) Value

func (n NullVersion) Value() (driver.Value, error)

Value is used when serializing a NullVersion for storage in the db.

type Version

type Version struct {
	// contains filtered or unexported fields
}

Version represents a CockroachDB (binary) version. Versions consist of three parts: a major version, written as "vX.Y" (which is typically the year and release number within the year), a patch version (the "Z" in "vX.Y.Z"), and sometimes one or more phases, sub-phases, and other suffixes. Note that CockroachDB versions are not semantic versions! You must use this package to parse and compare versions, in order to account for the variety of versions currently or historically in use.

func MustParse

func MustParse(str string) Version

MustParse is like Parse but panics on any error. Recommended as an initializer for global values.

func Parse

func Parse(str string) (Version, error)

Parse creates a version from a string.

func (Version) AtLeast

func (v Version) AtLeast(w Version) bool

AtLeast returns true if v >= w.

func (Version) Compare

func (v Version) Compare(w Version) int

Compare returns -1, 0, or +1 indicating the relative ordering of versions.

CockroachDB versions are not semantic versions. SemVer treats suffixes after the major.minor.patch quite generically; we have specific, known cases that have well-defined ordering requirements:

There are 4 known named prerelease phases. In order, they are: alpha, beta, rc, cloudonly. Pre-release versions will look like "v24.1.0-cloudonly.1" or "v23.2.0-rc.1".

Additionally, we have adhoc builds, which have suffixes like "-<n>-g<hex>", where <n> is an integer commit count past the branch point, and <hex> is the git SHA. These versions sort AFTER the corresponding "normal" version, eg "v24.1.0-1-g9cbe7c5281" is AFTER "v24.1.0".

A version can have both a pre-release and adhoc build suffix, like "v24.1.0-rc.2-14-g<hex>". In these cases, the pre-release portion has precedence, so this example would sort after v24.1.0-rc.2, but before v24.1.0-rc.3.

func (Version) CompareSeries

func (v Version) CompareSeries(w Version) int

Convenience wrapper for v.Major.Compare(w.Major())

func (Version) Empty

func (v Version) Empty() bool

Empty returns true if the version is the zero value.

func (Version) Equals

func (v Version) Equals(w Version) bool

func (Version) Format

func (v Version) Format(formatStr string) string

Format returns a string populated with parts of the version, using placeholders similar to the fmt package. The following placeholders are supported:

- %X: year - %Y: ordinal - %Z: patch - %P: phase name (one of "alpha", "beta", "rc", "cloudonly") - %p: phase sort order (see the top of version.go) - %o: phase ordinal (eg, the 1 in "v24.1.0-rc.1") - %s: phase sub-ordinal (eg the 2 in "v24.1.0-rc.1-cloudonly.2") - %n: adhoc build ordinal (eg the 12 in "v24.1.0-12-gabcdef") - %%: literal "%"

func (Version) IncPatch

func (v Version) IncPatch() (Version, error)

IncPatch returns a new version with the patch number incremented by 1. This method returns an error if the version is not a stable version.

func (Version) IncPreRelease

func (v Version) IncPreRelease() (Version, error)

IncPreRelease returns a new version with the pre-release part incremented by 1. This method returns an error if the version is not a pre-release.

func (Version) IsAdhocBuild

func (v Version) IsAdhocBuild() bool

IsAdhocBuild determines if the version is a adhoc build.

func (Version) IsCloudOnlyBuild

func (v Version) IsCloudOnlyBuild() bool

IsCloudOnlyBuild determines if the version is a CockroachDB Cloud specific build.

func (Version) IsCustomBuild

func (v Version) IsCustomBuild() bool

IsCustomBuild determines if the version is a adhoc build.

func (Version) IsCustomOrAdhocBuild

func (v Version) IsCustomOrAdhocBuild() bool

IsCustomOrAdhocBuild determines if the version is a adhoc build or adhoc build.

func (Version) IsPrerelease

func (v Version) IsPrerelease() bool

IsPrerelease determines whether the version is a pre-release version.

func (Version) LessThan

func (v Version) LessThan(w Version) bool

func (Version) Major

func (v Version) Major() MajorVersion

Major returns the version's MajorVersion (the "vX.Y" part)

func (Version) MarshalJSON

func (v Version) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler.

func (Version) Patch

func (v Version) Patch() int

Patch returns the version's patch number.

func (Version) SafeFormat

func (v Version) SafeFormat(p redact.SafePrinter, _ rune)

SafeFormat implements redact.SafePrinter.

func (*Version) Scan

func (v *Version) Scan(value interface{}) error

Scan implements database/sql.Scanner.

func (Version) String

func (v Version) String() string

String returns the original version string passed to Parse.

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(data []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

func (Version) Value

func (v Version) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

Jump to

Keyboard shortcuts

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