semver

package
v2.0.0-a4 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

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

func Less(a *Semver, b *Semver) bool

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

func SortStrings(values []string) []string

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 Err

type Err struct {
	Msg string
}

Err holds Semver's error messages

func (*Err) Error

func (err *Err) Error() string

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

func NewSemver(major int, minor int, patch int, suffix string) *Semver

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

func Parse(src []byte) (*Semver, error)

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

func ParseString(version string) (*Semver, error)

ParseString accepts a string instead of a byte slice.

func (*Semver) IncMajor

func (sv *Semver) IncMajor() error

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

func (sv *Semver) IncMinor() error

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

func (sv *Semver) IncPatch() error

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())

```

func (*Semver) String

func (sv *Semver) String() string

Return a *Semver as a encoded semver string.

```

sv := new(semver.Semver)
sv.Major = "1"
sv.Minor = "0"
sv.Patch = "3"
fmt.Printf("display semver 1.0.3 -> %q\n", sv.String())

```

func (*Semver) ToJSON

func (sv *Semver) ToJSON() []byte

ToJSON takes a version struct and returns JSON as byte slice

```

sv := new(semver.Semver)
sv.Major = "1"
sv.Minor = "0"
sv.Patch = "3"
fmt.Printf("JSON semver -> %s\n", sv.ToJSON())

```

Jump to

Keyboard shortcuts

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