semver

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 4 Imported by: 1

README

semver

Go Reference

Package semver contains Semantic Versioning 2.0.0 support for Go.

Documentation

Overview

Package semver contains Semantic Versioning 2.0.0 support for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(sv1, sv2 SemVer) (int, error)

Compare compares 'sv1' with 'sv2'. Compare returns -1 if 'sv1' is less than 'sv2', 0 if 'sv1' is equal to 'sv2', 1 if 'sv1' is more than 'sv2'.

func Less added in v0.4.0

func Less(sv1, sv2 SemVer) bool

Less reports whether 'sv1' is less than 'sv2'. If 'sv1' or/and 'sv2' is/are invalid, Less panics.

func Valid

func Valid(sv SemVer) error

Valid checks 'sv' for validity. If 'sv' is not valid corresponding error is returned.

Types

type SemVer

type SemVer struct {
	// Major contains SemVer's [major version].
	//
	// [major version]: https://semver.org/#spec-item-8
	Major int
	// Minor contains SemVer's [minor version].
	//
	// [minor version]: https://semver.org/#spec-item-7
	Minor int
	// Patch contains SemVer's [patch version].
	//
	// [patch version]: https://semver.org/#spec-item-6
	Patch int
	// PreRelease contains SemVer's [pre-release version].
	//
	// [pre-release version]: https://semver.org/#spec-item-9
	PreRelease string
	// Build contains SemVer's [build metadata].
	//
	// [build metadata]: https://semver.org/#spec-item-10
	Build string
}

SemVer represents Semantic Versioning Specification. SemVer's zero value is "0.0.0" version.

func Parse

func Parse(s string) (SemVer, error)

Parse converts the version string to a SemVer.

func (SemVer) CompareTo

func (v SemVer) CompareTo(other SemVer) (int, error)

CompareTo compares 'v' with 'other'. CompareTo returns -1 if 'v' is less than 'other', 0 if 'v' is equal to 'other', 1 if 'v' is more than 'other'.

func (SemVer) EqualTo added in v1.0.0

func (v SemVer) EqualTo(other SemVer) (bool, error)

EqualTo reports whether 'v' is equal to 'other'.

func (SemVer) IsValid

func (v SemVer) IsValid() bool

IsValid reports whether 'v' is valid.

func (SemVer) LessThan added in v1.0.0

func (v SemVer) LessThan(other SemVer) (bool, error)

LessThan reports whether 'v' is less than 'other'.

func (SemVer) MarshalText

func (v SemVer) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (SemVer) MoreThan added in v1.0.0

func (v SemVer) MoreThan(other SemVer) (bool, error)

MoreThan reports whether 'v' is more than 'other'.

func (SemVer) String

func (v SemVer) String() string

String implements the fmt.Stringer interface.

func (*SemVer) UnmarshalText

func (v *SemVer) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

Jump to

Keyboard shortcuts

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