Hashicorp go-version: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * https://github.com/hashicorp/go-version =Internal= =Overview=")
 
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
* https://github.com/hashicorp/go-version
* https://github.com/hashicorp/go-version
=Internal=
=Internal=
* [[Semantic_Versioning_in_Go#Hahicorp_go-version|Semantic Versioning in Go]]
=Overview=
=Overview=
=Installation=
<syntaxhighlight lang='bash'>
go get github.com/hashicorp/go-version
</syntaxhighlight>
=Programming Model=
<syntaxhighlight lang='go'>
v1, err := version.NewVersion("1.2")
v2, err := version.NewVersion("1.5+metadata")
// Comparison example. There is also GreaterThan, Equal, and just
// a simple Compare that returns an int allowing easy >=, <=, etc.
if v1.LessThan(v2) {
    fmt.Printf("%s is less than %s", v1, v2)
}
</syntaxhighlight>
[[Semantic_Versioning#Normal_(Core)_Version|Core]] version:
<syntaxhighlight lang='go'>
v.Core()
</syntaxhighlight>

Latest revision as of 18:26, 18 March 2024

External

Internal

Overview

Installation

go get github.com/hashicorp/go-version

Programming Model

v1, err := version.NewVersion("1.2")
v2, err := version.NewVersion("1.5+metadata")

// Comparison example. There is also GreaterThan, Equal, and just
// a simple Compare that returns an int allowing easy >=, <=, etc.
if v1.LessThan(v2) {
    fmt.Printf("%s is less than %s", v1, v2)
}

Core version:

v.Core()