version

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 8 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.LatestStableRelease()
  if err != nil {
    panic(err)
  }
  fmt.Println("Latest k0s version is: %s", latest)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Repo = "k0sproject/k0s"
View Source
var TimeOut = time.Second * 10

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Name string `json:"name"`
	URL  string `json:"browser_download_url"`
}

Asset describes a release asset

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 Release

type Release struct {
	URL        string  `json:"html_url"`
	TagName    string  `json:"tag_name"`
	PreRelease bool    `json:"prerelease"`
	Assets     []Asset `json:"assets"`
}

Release is a k0s release

func LatestRelease

func LatestRelease() (Release, error)

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

func LatestReleaseByPrerelease added in v0.1.1

func LatestReleaseByPrerelease(allowpre bool) (Release, error)

func LatestStableRelease

func LatestStableRelease() (Release, error)

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

func (*Release) GreaterThan

func (r *Release) GreaterThan(b fmt.Stringer) bool

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

func (*Release) String

func (r *Release) String() string

func (*Release) Version

func (r *Release) Version() (*Version, error)

type Version

type Version struct {
	goversion.Version
}

Version is a k0s version

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

Jump to

Keyboard shortcuts

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