37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
version.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-01-26 09:06 . Refactor imports
package utils
import (
"strings"
"github.com/blang/semver"
"github.com/rancher/rancher/pkg/catalog/utils/version"
)
func VersionBetween(a, b, c string) bool {
if a == "" && c == "" {
return true
} else if a == "" {
return !VersionGreaterThan(b, c)
} else if b == "" {
return true
} else if c == "" {
return !VersionGreaterThan(a, b)
}
return !VersionGreaterThan(a, b) && !VersionGreaterThan(b, c)
}
func formatVersion(v, rng string) (string, string) {
v = strings.TrimLeft(v, "v")
rng = strings.TrimLeft(rng, "v")
rng = strings.Replace(rng, ">v", ">", -1)
rng = strings.Replace(rng, ">=v", ">=", -1)
rng = strings.Replace(rng, "<v", "<", -1)
rng = strings.Replace(rng, "<=v", "<=", -1)
rng = strings.Replace(rng, "=v", "=", -1)
rng = strings.Replace(rng, "!v", "!", -1)
return v, rng
}
func VersionSatisfiesRange(v, rng string) (bool, error) {
v, rng = formatVersion(v, rng)
sv, err := semver.Parse(v)
if err != nil {
return false, err
}
rangeFunc, err := semver.ParseRange(rng)
if err != nil {
return false, err
}
return rangeFunc(sv), nil
}
func VersionGreaterThan(a, b string) bool {
return version.GreaterThan(a, b)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.7-rc4

搜索帮助