semver

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package semver implements the Semantic Versioning standard. It provides utilities for parsing, comparing, and incrementing version numbers.

Index

Constants

This section is empty.

Variables

View Source
var ErrSemver = errors.New("invalid semantic version specifier")

ErrSemver indicates a malformed version string.

Functions

This section is empty.

Types

type Semver

type Semver struct {
	Major uint
	Minor uint
	Patch uint

	// One or more prerelease identifiers. Nil if this is a normal release.
	Prerelease []string

	// One or more build metadata identifiers. Nil if not provided.
	// Most operations, including comparison, will ignore this field.
	Build []string
}

func Parse

func Parse(s string) (*Semver, error)

Parse converts a string to a Semver object. If the string is not a valid version specifier, it returns ErrSemver.

func (*Semver) Compare

func (v *Semver) Compare(other *Semver) int

Compare checks if two version specifiers are different. It returns:

  • -1 if the first version specifier has lower precedence
  • 0 if the version specifiers are equal
  • 1 if the first version specifier has higher precedence

Build metadata is ignored.

func (*Semver) IsStable

func (v *Semver) IsStable() bool

IsStable returns true if the version is not a prerelease, and the major version number is not 0. (Major version 0 is used for initial development).

func (*Semver) NextMajor

func (v *Semver) NextMajor() *Semver

NextMajor returns a new Semver object representing the next major version in the sequence.

func (*Semver) NextMinor

func (v *Semver) NextMinor() *Semver

NextMinor returns a new Semver object representing the next minor version in the sequence.

func (*Semver) NextPatch

func (v *Semver) NextPatch() *Semver

NextPatch returns a new Semver object representing the next patch version in the sequence.

func (*Semver) NextRelease

func (v *Semver) NextRelease() *Semver

NextRelease returns a new Semver object with prerelease and build information stripped. (It is used to determine the next stable release on a prerelease branch.)

func (*Semver) String

func (v *Semver) String() string

String returns the textual representation of the version object, in the format:

Major.Minor.Patch[-Prerelease][+Build]

Jump to

Keyboard shortcuts

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