semver

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package semver provides functionality to parse and process semantic versions, as they are used in multiple components of Constellation.

The official semantic versioning specification disallows leading "v" prefixes. However, the Constellation config uses the "v" prefix for versions to make version strings more recognizable. This package bridges the gap between Go's semver pkg (doesn't allow "v" prefix) and the Constellation config (requires "v" prefix).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sort

func Sort(list []Semver)

Sort sorts a list of semantic version strings using [ByVersion].

func ToStrings

func ToStrings(in []Semver) []string

ToStrings converts a slice of Semver to a slice of strings.

Types

type Semver

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

Semver represents a semantic version.

func New

func New(version string) (Semver, error)

New returns a Version from a string.

func NewFromInt

func NewFromInt(major, minor, patch int, prerelease string) Semver

NewFromInt constructs a new Semver from three integers and prerelease string: MAJOR.MINOR.PATCH-PRERELEASE.

func NewSlice

func NewSlice(in []string) ([]Semver, error)

NewSlice returns a slice of Semver from a slice of strings.

func (Semver) Compare

func (v Semver) Compare(other Semver) int

Compare compares two versions. It relies on the semver.Compare function internally. The result will be 0 if v == w, -1 if v < w, or +1 if v > w.

func (Semver) IsUpgradeTo

func (v Semver) IsUpgradeTo(other Semver) error

IsUpgradeTo returns if a version is an upgrade to another version. It checks if the version of v is greater than the version of other and allows a drift of at most one minor version.

func (Semver) Major

func (v Semver) Major() int

Major returns the major version of the object.

func (Semver) MajorMinorEqual

func (v Semver) MajorMinorEqual(other Semver) bool

MajorMinorEqual returns if the major and minor version of two versions are equal.

func (Semver) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Semver) MarshalYAML

func (v Semver) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaller interface.

func (Semver) Minor

func (v Semver) Minor() int

Minor returns the minor version of the object.

func (Semver) NextMinor

func (v Semver) NextMinor() string

NextMinor returns the next minor version in the format "vMAJOR.MINOR+1".

func (Semver) Patch

func (v Semver) Patch() int

Patch returns the patch version of the object.

func (Semver) Prerelease

func (v Semver) Prerelease() string

Prerelease returns the prerelease section of the object.

func (Semver) String

func (v Semver) String() string

String returns the string representation of the version.

func (*Semver) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Semver) UnmarshalYAML

func (v *Semver) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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