go-semver: github.com/coreos/go-semver/semver Index | Examples | Files

package semver

import "github.com/coreos/go-semver/semver"

Semantic Versions http://semver.org



Package Files

semver.go sort.go

func Sort Uses

func Sort(versions []*Version)

Sort sorts the given slice of Version

type PreRelease Uses

type PreRelease string

func (PreRelease) Slice Uses

func (p PreRelease) Slice() []string

type Version Uses

type Version struct {
    Major      int64
    Minor      int64
    Patch      int64
    PreRelease PreRelease
    Metadata   string

func Must Uses

func Must(v *Version, err error) *Version

Must is a helper for wrapping NewVersion and will panic if err is not nil.

func New Uses

func New(version string) *Version

func NewVersion Uses

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

func (*Version) BumpMajor Uses

func (v *Version) BumpMajor()

BumpMajor increments the Major field by 1 and resets all other fields to their default values

func (*Version) BumpMinor Uses

func (v *Version) BumpMinor()

BumpMinor increments the Minor field by 1 and resets all other fields to their default values

func (*Version) BumpPatch Uses

func (v *Version) BumpPatch()

BumpPatch increments the Patch field by 1 and resets all other fields to their default values

func (Version) Compare Uses

func (v Version) Compare(versionB Version) int

Compare tests if v is less than, equal to, or greater than versionB, returning -1, 0, or +1 respectively.

func (Version) Equal Uses

func (v Version) Equal(versionB Version) bool

Equal tests if v is equal to versionB.

func (Version) LessThan Uses

func (v Version) LessThan(versionB Version) bool

LessThan tests if v is less than versionB.


vA := New("1.2.3")
vB := New("3.2.1")

fmt.Printf("%s < %s == %t\n", vA, vB, vA.LessThan(*vB))


1.2.3 < 3.2.1 == true

func (Version) MarshalJSON Uses

func (v Version) MarshalJSON() ([]byte, error)

func (*Version) Set Uses

func (v *Version) Set(version string) error

Set parses and updates v from the given version string. Implements flag.Value

func (Version) Slice Uses

func (v Version) Slice() []int64

Slice converts the comparable parts of the semver into a slice of integers.

func (Version) String Uses

func (v Version) String() string

func (*Version) UnmarshalJSON Uses

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

func (*Version) UnmarshalYAML Uses

func (v *Version) UnmarshalYAML(unmarshal func(interface{}) error) error

type Versions Uses

type Versions []*Version

func (Versions) Len Uses

func (s Versions) Len() int

func (Versions) Less Uses

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

func (Versions) Swap Uses

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

Package semver imports 7 packages (graph) and is imported by 1857 packages. Updated 2019-07-06. Refresh now. Tools for package owners.