12345678910111213141516171819202122232425262728293031323334353637 |
- package semverutil
- import (
- "strings"
- "github.com/Masterminds/semver/v3"
- )
- func Compare(version1, comparison, version2 string) bool {
- clean := func(v string) string {
- if strings.Count(v, ".") > 2 {
- fields := strings.SplitN(v, ".", 4)
- v = strings.Join(fields[:3], ".")
- }
- return v
- }
- v, err := semver.NewVersion(clean(version1))
- if err != nil {
- return false
- }
- c, err := semver.NewConstraint(comparison + " " + clean(version2))
- if err != nil {
- return false
- }
- return c.Check(v)
- }
|