Goversify
Goversify is a powerful Go library for parsing, comparing, and validating version constraints. It supports Semantic Versioning (SemVer) and extended versioning schemes, making it ideal for version management and dependency resolution.
Features
- β
Strict SemVer Parsing: Ensures compliance with Semantic Versioning.
- β
Version Sorting & Comparison: Handles pre-release versions correctly.
- β
Flexible Constraints: Supports logical operators (
>, <, >=, <=, !=, ~, ^), wildcards (x, X, *), and complex constraints (AND & OR).
- β
Extended Versioning: Supports versions beyond MAJOR.MINOR.PATCH.
- β
Go-Native & Lightweight: No external dependencies.
π Table of Contents
π Installation
go get github.com/khulnasoft/goversify
π οΈ Usage
SemVer
v1, _ := semver.Parse("1.2.0")
v2, _ := semver.Parse("1.2.1")
if v1.LessThan(v2) {
fmt.Printf("%s is less than %s", v1, v2)
}
Sorting Versions
versionsRaw := []string{"1.1.0", "0.7.1", "1.4.0", "1.4.0-alpha"}
versions := make([]semver.Version, len(versionsRaw))
for i, raw := range versionsRaw {
v, _ := semver.Parse(raw)
versions[i] = v
}
sort.Sort(semver.Collection(versions))
Constraint Validation
v, _ := semver.Parse("2.1.0")
c, _ := semver.NewConstraints(">= 1.0, < 1.4 || > 2.0")
if c.Check(v) {
fmt.Printf("%s satisfies constraints '%s'", v, c)
}
π― Supported Constraint Operators
= : Exact match
!= : Not equal
> / < : Greater / Less than
>= / <= : Greater / Less than or equal
^ : Compatible updates (^1.2.3 β >=1.2.3, <2.0.0)
~ : Patch-level updates (~1.2.3 β >=1.2.3, <1.3.0)
*, x, X : Wildcard support (2.0.x β >=2.0.0, <2.1.0)
π Examples
Check out the examples directory for more in-depth usage.
π License
Goversify is licensed under the MIT License.
π Contribute
We welcome contributions! Feel free to open issues and submit PRs. π