semver

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: Apache-2.0 Imports: 4 Imported by: 5

README

LaunchDarkly Semantic Version Package

Circle CI Documentation

Overview

This Go package implements parsing and comparison of semantic version (semver) strings, as defined by the Semantic Versioning 2.0.0 specification.

Several semver implementations exist for Go. This implementation was designed for high performance in applications where semver operations may be done frequently, such as in the LaunchDarkly Go SDK. To that end, it does not use regular expressions and it never allocates data on the heap.

It does not include any additional functionality beyond what is defined in the Semantic Versioning 2.0.0 specification, such as comparison against range/wildcard expressions like ">=1.0.0" or "2.5.x".

This package has no external dependencies other than the regular Go runtime.

Supported Go versions

This version of the project has been tested with Go 1.14 and above.

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this project.

Documentation

Index

Constants

View Source
const (
	// ParseModeStrict is the default parsing mode, requiring a strictly correct version string with
	// all three required numeric components.
	ParseModeStrict = iota

	// ParseModeAllowMissingMinorAndPatch is a parsing mode in which the version string may omit the patch
	// version component ("2.1"), or both the minor and patch version components ("2"), in which case
	// they are assumed to be zero.
	ParseModeAllowMissingMinorAndPatch = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ParseMode

type ParseMode int

ParseMode is an enum-like type used with ParseAs.

type ValuesGenerator added in v1.0.2

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

func NewValuesGenerator added in v1.0.2

func NewValuesGenerator() *ValuesGenerator

func (*ValuesGenerator) AddValue added in v1.0.2

func (g *ValuesGenerator) AddValue(min, max int) *ValuesGenerator

func (ValuesGenerator) MakeAllPermutations added in v1.0.2

func (g ValuesGenerator) MakeAllPermutations() [][]int

func (ValuesGenerator) TestAll added in v1.0.2

func (g ValuesGenerator) TestAll(t *testing.T, action func(*testing.T, []int))

func (ValuesGenerator) TestAll1 added in v1.0.2

func (g ValuesGenerator) TestAll1(t *testing.T, action func(*testing.T, int))

func (ValuesGenerator) TestAll2 added in v1.0.2

func (g ValuesGenerator) TestAll2(t *testing.T, action func(*testing.T, int, int))

func (ValuesGenerator) TestAll3 added in v1.0.2

func (g ValuesGenerator) TestAll3(t *testing.T, action func(*testing.T, int, int, int))

func (ValuesGenerator) TestAll4 added in v1.0.2

func (g ValuesGenerator) TestAll4(t *testing.T, action func(*testing.T, int, int, int, int))

type Version

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

Version is a semantic version as defined by the Semantic Versions 2.0.0 standard (http://semver.org).

This type provides only parsing and simple precedence comparison, since those are the only features required by the LaunchDarkly Go SDK.

func Parse

func Parse(s string) (Version, error)

Parse attempts to parse a string into a Version. It only accepts strings that strictly match the specification, so extensions like a "v" prefix are not allowed.

If parsing fails, it returns a non-nil error as the second return value, and Version{} as the first.

func ParseAs

func ParseAs(s string, mode ParseMode) (Version, error)

ParseAs attempts to parse a string into a Version, using the specified ParseMode.

If parsing fails, it returns a non-nil error as the second return value, and Version{} as the first.

func (Version) ComparePrecedence

func (v Version) ComparePrecedence(other Version) int

ComparePrecedence compares this Version to another Version according to the canonical precedence rules. It returns -1 if v has lower precedence than other, 1 if v has higher precedence, or 0 if the same.

func (Version) GetBuild

func (v Version) GetBuild() string

GetBuild returns the build version component, or "" if there is none.

func (Version) GetMajor

func (v Version) GetMajor() int

GetMajor returns the numeric major version component.

func (Version) GetMinor

func (v Version) GetMinor() int

GetMinor returns the numeric minor version component.

func (Version) GetPatch

func (v Version) GetPatch() int

GetPatch returns the numeric patch version component.

func (Version) GetPrerelease

func (v Version) GetPrerelease() string

GetPrerelease returns the prerelease version component, or "" if there is none.

Jump to

Keyboard shortcuts

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