Documentation ¶
Overview ¶
semver is a semantic version number package used by dataset.
Authors R. S. Doiel, <rsdoiel@library.caltech.edu> and Tom Morrel, <tmorrell@library.caltech.edu>
Copyright (c) 2022, Caltech All rights not granted herein are expressly reserved by Caltech.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Less ¶
Less compares two semvers and if semver "a" is less than semver "b" returns true false otherwise.
```
versionA, versionB := "1.0.3", "1.4.2" svA, err := semver.Parse(versionA) ... svB, err := semver.Parse(versionB) ... if semver.Less(a, b) { fmt.Printf("%q is less than %q\n", versionA, versionB) } else if versionA == versionB { fmt.Printf("%q is equal to %q\n", versionA, versionB) } else { fmt.Printf("%q is greater than %q\n", versionA, versionB) }
```
func Sort ¶
func Sort(values []*Semver)
Sort semvers takes a slice of Semver, sorts them in ascending order.
```
versionA, versionB, vesionC := "1.0.3", "9.2.1", "0.3.6" svList := []*semver.Semver{} sv, _ := semver.Parse(versionA) svA, _ := semver.Parse(versionA)
```
func SortStrings ¶
SortStrings takes a list of strings which contain semvers convers the strings to a list of Semver structures, sorts the list and returns a new the list of strings and an error value
NOTE: Any unparsable semver values passed are skipped and not returned in the sortes list of strings.
Types ¶
type Semver ¶
type Semver struct { // Major version number (required, must be an integer as string) Major string `json:"major"` // Minor version number (required, must be an integer as string) Minor string `json:"minor"` // Patch level (optional, must be an integer as string) Patch string `json:"patch,omitempty"` // Suffix string, (optional, any string) Suffix string `json:"suffix,omitempty"` }
Semver holds the information to generate a semver string
func NewSemver ¶
NewSemver takes a major number, minor number, patch number and suffix string and returns a populated Semver.
```
version := semver.NewSemver(0, 0, 1, "-alpha") fmt.Printf("Version is now %q", version.String())
```
func Parse ¶
Parse takes a byte slice and returns a version struct, and an error value.
```
version := []byte("1.0.3") sv, err := semver.Parse(version) if err != nil { ... }
```
func ParseString ¶
ParseString accepts a string instead of a byte slice.
func (*Semver) IncMajor ¶
IncMajor increments a major version number, zeros minor and patch values. Returns an error if increment fails.
```
version := []byte("1.0.3") sv, err := semver.Parse(version) if err != nil { ... } sv.IncMajor() fmt.Printf("display 2.0.0 -> %q\n", sv.String())
```
func (*Semver) IncMinor ¶
IncMinor increments a minor version number and zeros the patch level or returns an error. Returns an error if increment fails.
```
version := []byte("1.0.3") sv, err := semver.Parse(version) if err != nil { ... } sv.IncMinor() fmt.Printf("display 1.1.0 -> %q\n", sv.String())
```
func (*Semver) IncPatch ¶
IncPatch increments the patch level if it is numeric or returns an error.
```
version := []byte("1.0.3") sv, err := semver.Parse(version) if err != nil { ... } sv.IncPatch() fmt.Printf("display 1.0.4 -> %q\n", sv.String())
```