go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.
译文:go-version是一个库,用于解析版本和版本约束,并根据一组约束验证版本。go-version 可以对版本集合进行正确排序,处理预发布/测试版,可以增加版本,等等。
文档
- github https://github.com/hashicorp/go-version
- pkg.go https://pkg.go.dev/github.com/hashicorp/go-version
- 语义化版本 2.0.0 https://semver.org/lang/zh-CN/
安装
go get github.com/hashicorp/go-version
示例
package main import ( "fmt" "github.com/hashicorp/go-version" ) func main() { v1, _ := version.NewVersion("1.2") v2, _ := version.NewVersion("2.1") if v1.LessThan(v2) { fmt.Printf("%s is less than %s", v1, v2) } // 1.2.0 is less than 2.1.0 }
参考