semver

package module
v0.0.0-...-31da48b Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 3 Imported by: 15

README

Semver

This is a simple Go package for handling semantic versioning (SemVer).

Features

  • Representation of semantic versions with major, minor, and patch version numbers, as well as optional pre-release and build metadata.
  • Comparison of versions with Less method, according to the rules described in the Semver Spec.
  • Equality check with Equal method.

Usage

Here's an example of how to use the Version struct:

v1 := semver.Version{ Major: 1, Minor: 0, Patch: 0, PreRelease: "alpha", Build: "001", }
fmt.Println(v1.String()) // Output: "1.0.0-alpha+001"
v2 := semver.Version{ Major: 1, Minor: 0, Patch: 1, }
if v1.Less(v2) { fmt.Println("v1 is less than v2") }
if !v1.Equal(v2) { fmt.Println("v1 is not equal to v2") }

Testing

You can run the unit tests included in the project with the following command:

go test

Contributing

If you would like to contribute, please fork the repository and use a feature branch. All contributions are welcome!

License

This project is open source, under the MIT License.# Semver

Documentation

Overview

Package semver implements semantic versioning.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Version

type Version struct {
	Major      int
	Minor      int
	Patch      int
	PreRelease string
	Build      string
}

Version is the major/minor/patch of the application.

func (Version) Equal

func (v Version) Equal(v2 Version) bool

Equal checks if the given version is identical to the current version

func (Version) Less

func (v Version) Less(v2 Version) bool

Less is a helper function to compare versions per https://semver.org/#spec-item-11. Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.

func (Version) String

func (v Version) String() string

String implements the Stringer interface. The version string is formatted per https://semver.org/ rules

Jump to

Keyboard shortcuts

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