🦔 semver and constraint parsing with a focus on performance
semver
provides semantic version and constraint parsing, comparison,
and testing.
There are many semver packages. This one aims to be the fastest at parsing
and comparing values, with low memory usage. On average, this package is roughly
ten times faster at parsing versions and constraints than the popular
Masterminds/semver
and hashicorp/go-version
packages. View more stats in
the benchmarks.
Versions can be compared with one another to determine which is newer. Constraints specify inclusions and exclusions of semver ranges that a given version must satisfy. Typically, constraints are used when expressing a dependency.
import (
"log"
"github.com/jbowes/semver"
)
func main() {
// Parse a version. Two versions can also be Compare()ed
ver, err := semver.Parse("1.0.2")
if err != nil {
log.Fatal("invalid semver")
}
// Parse a Constraint, typically used to express dependency
constr, err := semver.ParseConstraint(">=1.0.0")
if err != nil {
log.Fatalln("invalid constraint")
}
// Check if a Version satisfies a Constraint
if constr.Check(ver) {
log.Printf("%s satisfies constraint %s\n", ver, constr)
} else {
log.Printf("%s does not satisfy constraint %s\n", ver, constr)
}
}
For more usage and examples, see the GoDoc Reference
I would love your help!
semver
is still a work in progress. You can help by:
- Opening a pull request to resolve an open issue.
- Adding a feature or enhancement of your own! If it might be big, please open an issue first so we can discuss it.
- Improving this
README
or adding other documentation tosemver
. - Letting me know if you're using
semver
.