...

Package semver

import "github.com/blang/semver"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Variables
func NewBuildVersion(s string) (string, error)
func Sort(versions []Version)
type PRVersion
    func NewPRVersion(s string) (PRVersion, error)
    func (v PRVersion) Compare(o PRVersion) int
    func (v PRVersion) IsNumeric() bool
    func (v PRVersion) String() string
type Range
    func MustParseRange(s string) Range
    func ParseRange(s string) (Range, error)
    func (rf Range) AND(f Range) Range
    func (rf Range) OR(f Range) Range
type Version
    func Make(s string) (Version, error)
    func MustParse(s string) Version
    func New(s string) (vp *Version, err error)
    func Parse(s string) (Version, error)
    func ParseTolerant(s string) (Version, error)
    func (v Version) Compare(o Version) int
    func (v Version) EQ(o Version) bool
    func (v Version) Equals(o Version) bool
    func (v Version) GE(o Version) bool
    func (v Version) GT(o Version) bool
    func (v Version) GTE(o Version) bool
    func (v Version) LE(o Version) bool
    func (v Version) LT(o Version) bool
    func (v Version) LTE(o Version) bool
    func (v Version) MarshalJSON() ([]byte, error)
    func (v Version) NE(o Version) bool
    func (v *Version) Scan(src interface{}) (err error)
    func (v Version) String() string
    func (v *Version) UnmarshalJSON(data []byte) (err error)
    func (v Version) Validate() error
    func (v Version) Value() (driver.Value, error)
type Versions
    func (s Versions) Len() int
    func (s Versions) Less(i, j int) bool
    func (s Versions) Swap(i, j int)

Package files

json.go range.go semver.go sort.go sql.go

Variables

SpecVersion is the latest fully supported spec version of semver

var SpecVersion = Version{
    Major: 2,
    Minor: 0,
    Patch: 0,
}

func NewBuildVersion

func NewBuildVersion(s string) (string, error)

NewBuildVersion creates a new valid build version

func Sort

func Sort(versions []Version)

Sort sorts a slice of versions

type PRVersion

PRVersion represents a PreRelease Version

type PRVersion struct {
    VersionStr string
    VersionNum uint64
    IsNum      bool
}

func NewPRVersion

func NewPRVersion(s string) (PRVersion, error)

NewPRVersion creates a new valid prerelease version

func (PRVersion) Compare

func (v PRVersion) Compare(o PRVersion) int

Compare compares two PreRelease Versions v and o: -1 == v is less than o 0 == v is equal to o 1 == v is greater than o

func (PRVersion) IsNumeric

func (v PRVersion) IsNumeric() bool

IsNumeric checks if prerelease-version is numeric

func (PRVersion) String

func (v PRVersion) String() string

PreRelease version to string

type Range

Range represents a range of versions. A Range can be used to check if a Version satisfies it:

range, err := semver.ParseRange(">1.0.0 <2.0.0")
range(semver.MustParse("1.1.1") // returns true
type Range func(Version) bool

func MustParseRange

func MustParseRange(s string) Range

MustParseRange is like ParseRange but panics if the range cannot be parsed.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses a range and returns a Range. If the range could not be parsed an error is returned.

Valid ranges are:

A Range can consist of multiple ranges separated by space: Ranges can be linked by logical AND:

Ranges can also be linked by logical OR:

AND has a higher precedence than OR. It's not possible to use brackets.

Ranges can be combined by both AND and OR

func (Range) AND

func (rf Range) AND(f Range) Range

AND combines the existing Range with another Range using logical AND.

func (Range) OR

func (rf Range) OR(f Range) Range

OR combines the existing Range with another Range using logical OR.

type Version

Version represents a semver compatible version

type Version struct {
    Major uint64
    Minor uint64
    Patch uint64
    Pre   []PRVersion
    Build []string //No Precendence
}

func Make

func Make(s string) (Version, error)

Make is an alias for Parse, parses version string and returns a validated Version or error

func MustParse

func MustParse(s string) Version

MustParse is like Parse but panics if the version cannot be parsed.

func New

func New(s string) (vp *Version, err error)

New is an alias for Parse and returns a pointer, parses version string and returns a validated Version or error

func Parse

func Parse(s string) (Version, error)

Parse parses version string and returns a validated Version or error

func ParseTolerant

func ParseTolerant(s string) (Version, error)

ParseTolerant allows for certain version specifications that do not strictly adhere to semver specs to be parsed by this library. It does so by normalizing versions before passing them to Parse(). It currently trims spaces, removes a "v" prefix, and adds a 0 patch number to versions with only major and minor components specified

func (Version) Compare

func (v Version) Compare(o Version) int

Compare compares Versions v to o: -1 == v is less than o 0 == v is equal to o 1 == v is greater than o

func (Version) EQ

func (v Version) EQ(o Version) bool

EQ checks if v is equal to o.

func (Version) Equals

func (v Version) Equals(o Version) bool

Equals checks if v is equal to o.

func (Version) GE

func (v Version) GE(o Version) bool

GE checks if v is greater than or equal to o.

func (Version) GT

func (v Version) GT(o Version) bool

GT checks if v is greater than o.

func (Version) GTE

func (v Version) GTE(o Version) bool

GTE checks if v is greater than or equal to o.

func (Version) LE

func (v Version) LE(o Version) bool

LE checks if v is less than or equal to o.

func (Version) LT

func (v Version) LT(o Version) bool

LT checks if v is less than o.

func (Version) LTE

func (v Version) LTE(o Version) bool

LTE checks if v is less than or equal to o.

func (Version) MarshalJSON

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

MarshalJSON implements the encoding/json.Marshaler interface.

func (Version) NE

func (v Version) NE(o Version) bool

NE checks if v is not equal to o.

func (*Version) Scan

func (v *Version) Scan(src interface{}) (err error)

Scan implements the database/sql.Scanner interface.

func (Version) String

func (v Version) String() string

Version to string

func (*Version) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json.Unmarshaler interface.

func (Version) Validate

func (v Version) Validate() error

Validate validates v and returns error in case

func (Version) Value

func (v Version) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface.

type Versions

Versions represents multiple versions.

type Versions []Version

func (Versions) Len

func (s Versions) Len() int

Len returns length of version collection

func (Versions) Less

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

Less checks if version at index i is less than version at index j

func (Versions) Swap

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

Swap swaps two versions inside the collection by its indices

Subdirectories

Name Synopsis
..
examples
v4
examples