semver

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 2 Imported by: 4

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

The library supports the 'latest' and 'penultimate' Go versions defined in this file.

LaunchDarkly intends to keep those versions up-to-date with the Go project's latest two releases, which represents a support period of roughly 1 year. This policy is intended to match Go's official Release Policy: each major Go release is supported until there are two newer major releases.

Additionally, a 'minimum' version is tested in CI but not officially supported. This minimum version is found in go.mod. This version may be bumped from time to time as new Go features become available that are useful to the SDK.

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