semver

package module
v0.0.0-...-43f25fc Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2015 License: MIT Imports: 7 Imported by: 1

README

Semantic Versioning for Go

Build Coverage Issues License Documentation Chat

A Semantic Versioning library for Go.

❗ Still in heavy development and is not ready for usage. Please wait for the 1.0 release ❗

Covers version 2.0.0 of the semver specification.

Documentation on the syntax for the Satifies() method can be found here.

Installation

  go get github.com/hansrodtang/semver

For those who prefer it, you can also use gopkg.in:

  go get gopkg.in/hansrodtang/semver.v0

Usage

import github.com/hansrodtang/semver

v1, error := semver.New("1.5.0")
// do something with error
if v1.Satisfies("^1.0.0") {
  // do something
}

Benchmarks

Test Iterations Time
BenchmarkParseSimple 5000000 349 ns/op
BenchmarkParseComplex 1000000 1811 ns/op
BenchmarkCompareSimple 500000000 3.85 ns/op
BenchmarkCompareComplex 100000000 17.3 ns/op

Run the benchmarks yourself with:

go test github.com/hansrodtang/semver -bench=.

Tests

Run the tests with:

go test -cover github.com/hansrodtang/semver

License

This software is licensed under the MIT license.

Documentation

Overview

Package semver provides a Semantic Versioning library for Go. It allows you to parse and compare semver version strings. Covers version 2.0.0 of the semver specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Version

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

Version is the container for semver version data.

func Build

func Build(major, minor, patch uint64, extra ...[]string) *Version

Build accepts version numbers in uint64 and optional prerelease and metadata information in a string array. Build circumvents error checking, and is mostly used for testing.

func New

func New(version string) (*Version, error)

New accepts a valid semver version string and returns a Version struct. Returns error if the supplied string is an invalid semver version.

func (*Version) Compare

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

Compare accepts a Version and compares itself against it, returning >0 for greater than, 0 for equals and <0 for less than.

func (*Version) DecrementMajor

func (v *Version) DecrementMajor()

DecrementMajor decreases Major version by 1.

func (*Version) DecrementMinor

func (v *Version) DecrementMinor()

DecrementMinor decreases Minor version by 1.

func (*Version) DecrementPatch

func (v *Version) DecrementPatch()

DecrementPatch decreases Patch version by 1.

func (*Version) IncrementMajor

func (v *Version) IncrementMajor()

IncrementMajor increases Major version by 1.

func (*Version) IncrementMinor

func (v *Version) IncrementMinor()

IncrementMinor increases Minor version by 1.

func (*Version) IncrementPatch

func (v *Version) IncrementPatch()

IncrementPatch increases Patch version by 1.

func (Version) Major

func (v Version) Major() uint64

Major returns the major version.

func (*Version) MarshalJSON

func (p *Version) MarshalJSON() ([]byte, error)

func (Version) Metadata

func (v Version) Metadata() string

Metadata returns the metadata identifiers as a dot seperated string.

func (Version) Minor

func (v Version) Minor() uint64

Minor returns the minor version.

func (Version) Patch

func (v Version) Patch() uint64

Patch returns the patch version.

func (Version) Prerelease

func (v Version) Prerelease() string

Prerelease returns the prerelease identifiers as a dot seperated string.

func (Version) Satifies

func (v Version) Satifies(requirements string) (bool, error)

Satifies accepts a set of comparators and version numbers as a string. The syntax for the string is documented here: https://www.npmjs.org/doc/misc/semver.html Returns true if Version matches the comparators, false if it does not.

func (*Version) SetMajor

func (v *Version) SetMajor(major uint64)

SetMajor accepts a uint64 to change the currently set major version.

func (*Version) SetMetadata

func (v *Version) SetMetadata(identifiers ...string) error

SetMetadata accepts a series of strings to form the metadata identifiers. Returns error if any of the supplied strings aren't a valid metadata identifier.

func (*Version) SetMinor

func (v *Version) SetMinor(minor uint64)

SetMinor accepts a uint64 to change the currently set minor version.

func (*Version) SetPatch

func (v *Version) SetPatch(patch uint64)

SetPatch accepts a uint64 to change the currently set patch version.

func (*Version) SetPrerelease

func (v *Version) SetPrerelease(identifiers ...string) error

SetPrerelease accepts a series of strings to form the prerelease identifiers. Returns error if any of the supplied strings aren't a valid prerelease identifier.

func (Version) String

func (v Version) String() string

String returns a valid semver string based on the data contained in Version.

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(b []byte) error

type Versions

type Versions []*Version

func (Versions) Len

func (v Versions) Len() int

func (Versions) Less

func (v Versions) Less(i, j int) bool

func (Versions) Swap

func (v Versions) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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