A SemVer Package is a package that implements the Semantic Versioning (SemVer) specification. SemVer is a widely adopted standard for versioning software libraries and applications, making it easier for developers to understand when and what changes have been made to a package.
go get oss.nandlabs.io/golly/semver
- Adheres to the SemVer 2.0.0 specification
- Easy to use API for parsing, comparing and generating SemVer versions
- Supports pre-release and build metadata
- Written in modern Golang and follows best practices
Here is an example of how to use the SemVer package in a Golang project:
package main
import (
"fmt"
"oss.nandlabs.io/golly/semver"
)
func main() {
version, err := semver.Parse("v1.2.3")
if err != nil {
fmt.Println(err)
}
fmt.Printf("Major :: %d", version.CurrentMajor())
fmt.Printf("Minor :: %d", version.CurrentMinor())
fmt.Printf("Patch :: %d", version.CurrentPatch())
metadataVersion, err := semver.Parse("v1.2.3-SNAPSHOT")
if err != nil {
fmt.Println(err)
}
fmt.Printf("Major :: %d", metadataVersion.CurrentMajor())
fmt.Printf("Minor :: %d", metadataVersion.CurrentMinor())
fmt.Printf("Patch :: %d", metadataVersion.CurrentPatch())
fmt.Printf("Pre-Release :: %s", metadataVersion.CurrentPreRelease)
}