Documentation
¶
Overview ¶
package version implements a k0s version type and functions to parse and compare versions
Index ¶
- Constants
- Variables
- type Collection
- type Constraint
- type Delta
- type Version
- func (v *Version) AirgapDownloadURL(arch string) string
- func (v *Version) Base() string
- func (v *Version) Clone() *Version
- func (v *Version) ComparableFields() comparableFields
- func (v *Version) Compare(b *Version) int
- func (v *Version) Delta(b *Version) Delta
- func (v *Version) DocsURL() string
- func (v *Version) DownloadURL(os, arch string) string
- func (v *Version) Equal(b *Version) bool
- func (v *Version) GreaterThan(b *Version) bool
- func (v *Version) GreaterThanOrEqual(b *Version) bool
- func (v *Version) IsK0s() bool
- func (v *Version) IsPrerelease() bool
- func (v *Version) IsZero() bool
- func (v *Version) K0s() (int, bool)
- func (v *Version) LessThan(b *Version) bool
- func (v *Version) LessThanOrEqual(b *Version) bool
- func (v *Version) Major() string
- func (v *Version) MarshalText() ([]byte, error)
- func (v *Version) MarshalYAML() (interface{}, error)
- func (v *Version) Metadata() string
- func (v *Version) Minor() string
- func (v *Version) Patch() string
- func (v *Version) Prerelease() string
- func (v *Version) Satisfies(constraint Constraint) bool
- func (v *Version) Segments() []int
- func (v *Version) Segments64() []int64
- func (v *Version) String() string
- func (v *Version) URL() string
- func (v *Version) UnmarshalText(text []byte) error
- func (v *Version) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (v *Version) WithK0s(n int) *Version
Examples ¶
Constants ¶
const (
BaseUrl = "https://github.com/k0sproject/k0s/"
)
Variables ¶
var Timeout = time.Second * 10
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection []*Version
Collection is a type that implements the sort.Interface interface so that versions can be sorted.
func NewCollection ¶
func NewCollection(versions ...string) (Collection, error)
func (Collection) Len ¶
func (c Collection) Len() int
func (Collection) Less ¶
func (c Collection) Less(i, j int) bool
func (Collection) Swap ¶
func (c Collection) Swap(i, j int)
type Constraint ¶ added in v0.8.0
type Constraint struct {
// contains filtered or unexported fields
}
func MustConstraint ¶ added in v0.4.0
func MustConstraint(cs string) Constraint
MustConstraint is like NewConstraint but panics if the constraint is invalid.
func NewConstraint ¶ added in v0.4.0
func NewConstraint(cs string) (Constraint, error)
NewConstraint parses a string and returns a Contraint and an error if the parsing fails.
func (Constraint) Check ¶ added in v0.8.0
func (cs Constraint) Check(v *Version) bool
Check returns true if the given version satisfies all of the constraints.
func (Constraint) CheckString ¶ added in v0.8.0
func (cs Constraint) CheckString(v string) bool
CheckString is like Check but takes a string version. If the version is invalid, it returns false.
func (Constraint) String ¶ added in v0.8.0
func (cs Constraint) String() string
String returns the constraint as a string.
type Delta ¶ added in v0.8.0
type Delta struct { MajorUpgrade bool MinorUpgrade bool PatchUpgrade bool K0sUpgrade bool Equal bool Downgrade bool PrereleaseOnly bool BuildMetadataChange bool Consecutive bool // contains filtered or unexported fields }
Delta represents the differences between two versions.
Example ¶
package main import ( "fmt" "github.com/k0sproject/version" ) func main() { a, _ := version.NewVersion("v1.0.0") b, _ := version.NewVersion("v1.2.1") delta := version.NewDelta(a, b) fmt.Printf("patch upgrade: %t\n", delta.PatchUpgrade) fmt.Println(delta.String()) }
Output: patch upgrade: false a non-consecutive minor upgrade from v1.0 to v1.2
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version is a k0s version
func Latest ¶ added in v0.3.0
LatestVersion returns the semantically sorted latest version even if it is a prerelease from the online repository
func LatestByPrerelease ¶ added in v0.3.0
LatestByPrerelease returns the latest released k0s version, if preok is true, prereleases are also accepted.
func LatestStable ¶ added in v0.3.0
LatestStable returns the semantically sorted latest non-prerelease version from the online repository
func MustParse ¶ added in v0.4.0
MustParse is like NewVersion but panics if the version cannot be parsed. It simplifies safe initialization of global variables.
func NewVersion ¶
NewVersion returns a new Version object from a string representation of a k0s version
func (*Version) AirgapDownloadURL ¶ added in v0.3.0
AirgapDownloadURL returns the k0s airgap bundle download URL for the k0s version
func (*Version) Base ¶ added in v0.7.0
Base returns the version as a string without the k0s or metadata part (eg v1.2.3+k0s.4 -> v1.2.3)
func (*Version) ComparableFields ¶ added in v0.7.0
func (v *Version) ComparableFields() comparableFields
ComparableFields returns the comparable fields of the k0s version
func (*Version) Compare ¶
Compare returns 0 if the k0s version is equal to the supplied version, 1 if it's greater and -1 if it's lower
func (*Version) DownloadURL ¶ added in v0.3.0
DownloadURL returns the k0s binary download URL for the k0s version
func (*Version) GreaterThan ¶
GreaterThan returns true if the version is greater than the supplied version
func (*Version) GreaterThanOrEqual ¶
GreaterThanOrEqual returns true if the version is greater than the supplied version or equal
func (*Version) IsPrerelease ¶ added in v0.7.0
IsPrerelease returns true if the k0s version is a prerelease version
func (*Version) K0s ¶ added in v0.7.0
K0s returns the k0s version (eg 4 from v1.2.3-k0s.4) and true if the version is a k0s version. Otherwise it returns 0 and false.
func (*Version) LessThanOrEqual ¶
LessThanOrEqual returns true if the version is lower than the supplied version or equal
func (*Version) MarshalText ¶ added in v0.7.0
MarshalText implements the encoding.TextMarshaler interface (used as fallback by encoding/json and yaml.v3).
func (*Version) MarshalYAML ¶ added in v0.4.0
MarshalYAML implements the yaml.v2 Marshaler interface.
func (*Version) Metadata ¶ added in v0.7.0
Metadata returns the metadata part of the k0s version (eg 123abc from v1.2.3+k0s.1.123abc)
func (*Version) Minor ¶ added in v0.8.0
Minor returns a string like "v2.3" from a version like 2.3.0
func (*Version) Patch ¶ added in v0.8.0
Patch returns a string like "v2.3.4" from a version like 2.3.4-rc.1
func (*Version) Prerelease ¶ added in v0.7.0
Prerelease returns the prerelease part of the k0s version (eg rc1 from v1.2.3-rc1).
func (*Version) Satisfies ¶ added in v0.4.0
func (v *Version) Satisfies(constraint Constraint) bool
Satisfies returns true if the version satisfies the supplied constraint
func (*Version) Segments ¶ added in v0.7.0
Segments returns the numerical segments of the version. The returned slice is always maxSegments long. Missing segments are zeroes. Eg 1,1,0 from v1.1
func (*Version) Segments64 ¶ added in v0.7.0
Segments64 returns the numerical segments of the k0s version as int64 (eg 1,2,3 from v1.2.3). Missing segments are zeroes.
func (*Version) String ¶ added in v0.3.0
String returns a v-prefixed string representation of the k0s version
func (*Version) URL ¶ added in v0.3.0
URL returns an URL to the release information page for the k0s version
func (*Version) UnmarshalText ¶ added in v0.7.0
UnmarshalText implements the encoding.TextUnmarshaler interface (used as fallback by encoding/json and yaml.v3).
func (*Version) UnmarshalYAML ¶ added in v0.4.0
UnmarshalYAML implements the yaml.v2 Unmarshaler interface.