Documentation
¶
Index ¶
- Variables
- func FuzzNewConstraint(f *testing.F)
- func FuzzNewVersion(f *testing.F)
- func FuzzStrictNewVersion(f *testing.F)
- type Collection
- type Constraints
- type Version
- func (v *Version) Compare(o *Version) int
- func (v *Version) Copy() Version
- func (v *Version) Equal(o *Version) bool
- func (v *Version) GreaterThan(o *Version) bool
- func (v *Version) IncLast() Version
- func (v *Version) IncMajor() Version
- func (v *Version) IncMinor() Version
- func (v *Version) IncPart(part int) Version
- func (v *Version) IncPatch() Version
- func (v *Version) LessThan(o *Version) bool
- func (v *Version) Major() uint64
- func (v Version) MarshalJSON() ([]byte, error)
- func (v Version) MarshalText() ([]byte, error)
- func (v *Version) Metadata() string
- func (v *Version) Minor() uint64
- func (v *Version) Original() string
- func (v *Version) Part(part int) uint64
- func (v *Version) PartsNumber() int
- func (v *Version) Patch() uint64
- func (v *Version) Prerelease() string
- func (v *Version) Scan(value interface{}) error
- func (v *Version) SetMetadata(metadata string) (Version, error)
- func (v *Version) SetPrerelease(prerelease string) (Version, error)
- func (v *Version) String() string
- func (v *Version) UnmarshalJSON(b []byte) error
- func (v *Version) UnmarshalText(text []byte) error
- func (v Version) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSemVer is returned a version is found to be invalid when // being parsed. ErrInvalidSemVer = errors.New("invalid Semantic Version") // ErrEmptyString is returned when an empty string is passed in for parsing. ErrEmptyString = errors.New("version string empty") // ErrInvalidCharacters is returned when invalid characters are found as // part of a version ErrInvalidCharacters = errors.New("invalid characters in version") // ErrSegmentStartsZero is returned when a version segment starts with 0. // This is invalid in SemVer. ErrSegmentStartsZero = errors.New("version segment starts with 0") // ErrInvalidMetadata is returned when the metadata is an invalid format ErrInvalidMetadata = errors.New("invalid Metadata string") // ErrInvalidPrerelease is returned when the pre-release is an invalid format ErrInvalidPrerelease = errors.New("invalid Prerelease string") )
Functions ¶
func FuzzNewConstraint ¶ added in v0.1.0
func FuzzNewVersion ¶ added in v0.1.0
func FuzzStrictNewVersion ¶ added in v0.1.0
Types ¶
type Collection ¶
type Collection []*Version
Collection is a collection of Version instances and implements the sort interface. See the sort package for more details. https://golang.org/pkg/sort/
func (Collection) Len ¶
func (c Collection) Len() int
Len returns the length of a collection. The number of Version instances on the slice.
func (Collection) Less ¶
func (c Collection) Less(i, j int) bool
Less is needed for the sort interface to compare two Version objects on the slice. If checks if one is less than the other.
func (Collection) Swap ¶
func (c Collection) Swap(i, j int)
Swap is needed for the sort interface to replace the Version objects at two different positions in the slice.
type Constraints ¶
type Constraints struct {
// contains filtered or unexported fields
}
Constraints is one or more constraint that a semantic version can be checked against.
func NewConstraint ¶
func NewConstraint(c string) (*Constraints, error)
NewConstraint returns a Constraints instance that a Version instance can be checked against. If there is a parse error it will be returned.
func (Constraints) Check ¶
func (cs Constraints) Check(v *Version) bool
Check tests if a version satisfies the constraints.
func (Constraints) MarshalText ¶ added in v0.1.0
func (cs Constraints) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (Constraints) String ¶
func (cs Constraints) String() string
func (*Constraints) UnmarshalText ¶ added in v0.1.0
func (cs *Constraints) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version represents a single semantic version.
func NewVersion ¶
NewVersion parses a given version and returns an instance of Version or an error if unable to parse the version. This version allow a `v` prefix
func NewVersionByParts ¶ added in v0.1.0
func StrictNewVersion ¶
StrictNewVersion parses a given version and returns an instance of Version or an error if unable to parse the version. Only parses valid semantic versions. Performs checking that can find errors within the version. If you want to allow optional v prefix, use the NewVersion() function.
func (*Version) Compare ¶
Compare compares this version to another one. It returns -1, 0, or 1 if the version smaller, equal, or larger than the other version.
Versions are compared by X.Y.Z. Build metadata is ignored. Prerelease is lower than the version without a prerelease. Compare always takes into account prereleases. If you want to work with ranges using typical range syntaxes that skip prereleases if the range is not looking for them use constraints.
func (*Version) Equal ¶
Equal tests if two versions are equal to each other. Note, versions can be equal with different metadata since metadata is not considered part of the comparable version.
func (*Version) GreaterThan ¶
GreaterThan tests if one version is greater than another one.
func (*Version) IncLast ¶ added in v0.1.0
IncLast produces the next version on last part Same as IncPart(len(v.PartsNumber()))
func (*Version) IncPart ¶
IncPart produces the next version on specific part If the part is not exist - increase the part number to specific - do same as last part If the part is last part - if the pre exist, will remove pre and metadata and won't increase the part - if the pre not exist, will remove metadata and increase the part If the part is not last part - will remove pre and metadata and increase the part - following parts will be set to zero
func (Version) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface.
func (Version) MarshalText ¶ added in v0.1.0
MarshalText implements the encoding.TextMarshaler interface.
func (*Version) PartsNumber ¶
func (*Version) Prerelease ¶
Prerelease returns the pre-release version.
func (*Version) SetMetadata ¶
SetMetadata defines metadata value. Value must not include the required 'plus' prefix.
func (*Version) SetPrerelease ¶
SetPrerelease defines the prerelease value. Value must not include the required 'hyphen' prefix.
func (*Version) String ¶
String converts a Version object to a string. Note, if the original version contained a leading v this version will not. See the Original() method to retrieve the original value. Semantic Versions don't contain a leading v per the spec. Instead it's optional on implementation.
func (*Version) UnmarshalJSON ¶
UnmarshalJSON implements JSON.Unmarshaler interface.
func (*Version) UnmarshalText ¶ added in v0.1.0
UnmarshalText implements the encoding.TextUnmarshaler interface.