Documentation
¶
Index ¶
- Variables
- type Version
- func (v *Version) BuildMetadata() []string
- func (v *Version) BumpMajor() error
- func (v *Version) BumpMinor() error
- func (v *Version) BumpPatch() error
- func (v *Version) BumpPrerelease() error
- func (v *Version) Clone() *Version
- func (v *Version) Compare(v2 *Version) int
- func (v *Version) Prerelease() []string
- func (v *Version) SetBuildMetadata(meta string) error
- func (v *Version) SetPrelease(pre string) error
- func (v *Version) String() string
- type Versions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotNumeric is returned when a given field is expected to be a number. // Numbers cannot be zero-padded in semver. ErrNotNumeric = errors.New("field must be numeric and not zero-padded") // ErrUnparseable is returned when parsing a semver that is not valid ErrUnparseable = errors.New("could not parse string as semantic version") )
Functions ¶
This section is empty.
Types ¶
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version represents a semantic version compliant with the v2.0.0 standard specified at https://semver.org
func ParseStrict ¶
ParseStrict parses a string into a semantic version that strictly follows the standard, and validates it
func ParseTolerant ¶
ParseTolerant allows more leeway in parsing -- it allows an optional "v" at the beginning of the string, and it allows minor or patch to be missing, to be replaced with zeroes. HOWEVER, if patch is present, then minor must be present as well. It validates the version before returning
func (*Version) BuildMetadata ¶
func (*Version) BumpMajor ¶
BumpMajor attempts to increment the major field of the version by 1. If it's successful, it resets the minor and patch fields to 0 and unsets the prerelease and build metadata fields. It only errors if major is not parsable by (*math/big.Int).SetString, which should not occur.
func (*Version) BumpMinor ¶
BumpMinor attempts to increment the minor field of the version by 1. If it's successful, it resets the patch field to 0 and unsets the prerelease and build metadata fields. It only errors if minor is not parsable by (*math/big.Int).SetString, which should not occur.
func (*Version) BumpPatch ¶
BumpPatch attempts to increment the patch field of the version by 1. If it's successful, it unsets the prerelease and build metadata fields. It only errors if major is not parsable by (*math/big.Int).SetString, which should not occur.
func (*Version) BumpPrerelease ¶
BumpPrerelease inspects the version's prerelease information, and if the last field is a number, increment it. If it is not, append ".1" to the end of the prerelease information. It returns an error if prerelease is empty.
func (*Version) Compare ¶
Compare compares two semantic versions based on the rules set out in the standard. If v is smaller than v2, Compare returns a value < 0. If v is larger than v2, Compare returns a value > 0. In both cases, the actual value returned is variable, but will conform to that signature. If the two versions are equivalent according to the standard, Compare returns 0.
func (*Version) Prerelease ¶
func (*Version) SetBuildMetadata ¶
SetBuildMetadata sets the build metadata information for the version. If the passed string is empty or contains only whitespace, it unsets the prerelease info. If it has data, it must be a dot-separated string, where each substring contains only letters, numbers, and dashes.
func (*Version) SetPrelease ¶
SetPrerelease sets the prerelease information for the version. If the passed string is empty or contains only whitespace, it unsets the prerelease info. If it has data, it must be a dot-separated string, where each substring contains only letters, numbers, and dashes. If a substring is fully numeric, it must not be zero padded (if it starts with 0, it must be exactly 0).