version

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 12 Imported by: 8

README

version

A go-language package for managing k0s version numbers. It is based on hashicorp/go-version but adds sorting and comparison capabilities for the k0s version numbering scheme which requires additional sorting by the build tag.

Usage

Basic comparison
import (
	"fmt"
	"github.com/k0sproject/version"
)

func main() {
	a := version.MustParse("1.23.3+k0s.1")
	b := version.MustParse("1.23.3+k0s.2")
	fmt.Printf("a is greater than b: %t\n", a.GreaterThan(b))
	fmt.Printf("a is less than b: %t\n", a.LessThan(b))
	fmt.Printf("a is equal to b: %t\n", a.Equal(b))
}

Outputs:

a is greater than b: false
a is less than b: true
a is equal to b: false
Check online for latest version
import (
	"fmt"
	"github.com/k0sproject/version"
)

func main() {
	latest, err := version.Latest()
	if err != nil {
		panic(err)
	}
	fmt.Printf("Latest k0s version is: %s\n", latest)
}
k0s_sort executable

A command-line interface to the package. Can be used to sort lists of versions or to obtain the latest version number.

Usage: k0s_sort [options] [filename ...]
  -l	only print the latest version
  -o	print the latest version from online
  -s	omit prerelease versions
  -v	print k0s_sort version

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseUrl = "https://github.com/k0sproject/k0s/"
View Source
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) MarshalJSON added in v0.4.0

func (c *Collection) MarshalJSON() ([]byte, error)

UnmarshalText implements the json.Marshaler interface.

func (*Collection) MarshalYAML added in v0.4.0

func (c *Collection) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (Collection) Swap

func (c Collection) Swap(i, j int)

func (*Collection) UnmarshalJSON added in v0.4.0

func (c *Collection) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Collection) UnmarshalYAML added in v0.4.0

func (c *Collection) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Constraints added in v0.4.0

type Constraints []constraint

Constraints is a collection of version constraint rules that can be checked against a version.

func MustConstraint added in v0.4.0

func MustConstraint(cs string) Constraints

MustConstraint is like NewConstraint but panics if the constraint is invalid.

func NewConstraint added in v0.4.0

func NewConstraint(cs string) (Constraints, error)

NewConstraint parses a string into a Constraints object that can be used to check if a given version satisfies the constraint.

func (Constraints) Check added in v0.4.0

func (cs Constraints) Check(v *Version) bool

Check returns true if the given version satisfies all of the constraints.

func (Constraints) CheckString added in v0.4.0

func (cs Constraints) CheckString(v string) bool

CheckString is like Check but takes a string version. If the version is invalid, it returns false.

func (Constraints) String added in v0.4.1

func (cs Constraints) String() string

String returns the constraint as a string.

type Version

type Version struct {
	goversion.Version
}

Version is a k0s version

func Latest added in v0.3.0

func Latest() (*Version, error)

LatestVersion returns the semantically sorted latest version even if it is a prerelease from the online repository

func LatestByPrerelease added in v0.3.0

func LatestByPrerelease(allowpre bool) (*Version, error)

LatestByPrerelease returns the latest released k0s version, if preok is true, prereleases are also accepted.

func LatestStable added in v0.3.0

func LatestStable() (*Version, error)

LatestStable returns the semantically sorted latest non-prerelease version from the online repository

func MustParse added in v0.4.0

func MustParse(v string) *Version

MustParse is like NewVersion but panics if the version cannot be parsed. It simplifies safe initialization of global variables.

func NewVersion

func NewVersion(v string) (*Version, error)

NewVersion returns a new Version created from the supplied string or an error if the string is not a valid version number

func (*Version) AirgapDownloadURL added in v0.3.0

func (v *Version) AirgapDownloadURL(arch string) string

AirgapDownloadURL returns the k0s airgap bundle download URL for the k0s version

func (*Version) Compare

func (v *Version) Compare(b *Version) int

Compare compares two versions and returns one of the integers: -1, 0 or 1 (less than, equal, greater than)

func (*Version) DocsURL added in v0.3.0

func (v *Version) DocsURL() string

DocsURL returns the documentation URL for the k0s version

func (*Version) DownloadURL added in v0.3.0

func (v *Version) DownloadURL(os, arch string) string

DownloadURL returns the k0s binary download URL for the k0s version

func (*Version) Equal

func (v *Version) Equal(b *Version) bool

Equal returns true if the version is equal to the supplied version

func (*Version) GreaterThan

func (v *Version) GreaterThan(b *Version) bool

GreaterThan returns true if the version is greater than the supplied version

func (*Version) GreaterThanOrEqual

func (v *Version) GreaterThanOrEqual(b *Version) bool

GreaterThanOrEqual returns true if the version is greater than the supplied version or equal

func (*Version) IsZero added in v0.4.2

func (v *Version) IsZero() bool

func (*Version) LessThan

func (v *Version) LessThan(b *Version) bool

LessThan returns true if the version is lower than the supplied version

func (*Version) LessThanOrEqual

func (v *Version) LessThanOrEqual(b *Version) bool

LessThanOrEqual returns true if the version is lower than the supplied version or equal

func (*Version) MarshalJSON added in v0.4.0

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

MarshalJSON implements the json.Marshaler interface.

func (*Version) MarshalYAML added in v0.4.0

func (v *Version) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*Version) Satisfies added in v0.4.0

func (v *Version) Satisfies(constraint Constraints) bool

Satisfies returns true if the version satisfies the supplied constraint

func (*Version) String added in v0.3.0

func (v *Version) String() string

String returns a v-prefixed string representation of the k0s version

func (*Version) URL added in v0.3.0

func (v *Version) URL() string

URL returns an URL to the release information page for the k0s version

func (*Version) UnmarshalJSON added in v0.4.0

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Version) UnmarshalYAML added in v0.4.0

func (v *Version) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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