代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。