version

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 9 Imported by: 12

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.NewVersion("1.23.3+k0s.1")
  b := version.NewVersion("1.23.3+k0s.2")
  fmt.Println("a is greater than b: %t", a.GreaterThan(b))
  fmt.Println("a is less than b: %t", a.LessThan(b))
  fmt.Println("a is equal to b: %t", 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.Println("Latest k0s version is: %s", latest)
}

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 (v Collection) Len() int

func (Collection) Less

func (v Collection) Less(i, j int) bool

func (Collection) Swap

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

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 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) 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) 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

Directories

Path Synopsis
cmd
k0s_sort command

Jump to

Keyboard shortcuts

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