An open API service indexing awesome lists of open source software.

https://github.com/foxcapades/gversion

Version parsing
https://github.com/foxcapades/gversion

Last synced: over 1 year ago
JSON representation

Version parsing

Awesome Lists containing this project

README

          

= gVersion

image:https://img.shields.io/github/v/tag/foxcapades/gVersion[GitHub tag (latest SemVer)]
image:https://img.shields.io/github/go-mod/go-version/foxcapades/gVersion[GitHub go.mod Go version]
image:https://img.shields.io/github/license/foxcapades/gVersion[GitHub]
image:https://img.shields.io/badge/api-docs-ff69b4[title="API Docs", link=https://pkg.go.dev/github.com/foxcapades/gVersion/v1/pkg/semver]
image:https://github.com/Foxcapades/gVersion/workflows/Go/badge.svg[Go]
image:https://codecov.io/gh/Foxcapades/gVersion/branch/main/graph/badge.svg?token=E4WD9IURJL[title=codecov, link=https://codecov.io/gh/Foxcapades/gVersion]

A simple version string representation/parser for dealing with version strings
as their individual components.

Additionally, this library imports no stdlib packages apart from `unsafe`.

.Example
[source, go]
----
func ExampleParse() {
version := "v1.23.0-alpha+b58"

ver, _ := semver.Parse(version)

fmt.Println(ver.Major)
fmt.Println(ver.Minor)
fmt.Println(ver.Patch)
fmt.Println(ver.Prerelease)
fmt.Println(ver.Build)

// Output:
// 1
// 23
// 0
// [alpha]
// [b58]
}
----

Version types are comparable using the methods `Equal`, `Equivalent`,
`IsBefore`, and `IsAfter`.

*_Equal vs Equivalent_*

The `Equal` method compares all components of 2 Version structs, including the
prerelease and build tags.

The `Equivalent` method compares 2 Version structs following the semantic
versioning rule that gives `1.0.0` and `1.0.0+b23` the same precedence in
version ordering.