gitlab.com/evatix-go/core@v1.3.55/coreversion/all-compare.go (about) 1 package coreversion 2 3 import ( 4 "gitlab.com/evatix-go/core/corecmp" 5 "gitlab.com/evatix-go/core/corecomparator" 6 ) 7 8 func Compare( 9 left, 10 right *Version, 11 ) corecomparator.Compare { 12 compare, isApplicable := hasDeductUsingNilNess(left, right) 13 14 if isApplicable { 15 return compare 16 } 17 18 majorVersionCompare := corecmp.Integer( 19 left.VersionMajor, 20 right.VersionMajor) 21 22 if majorVersionCompare.IsNotEqualLogically() { 23 return majorVersionCompare 24 } 25 26 // proceed only on equal 27 minorVersionCompare := corecmp.Integer( 28 left.VersionMinor, 29 right.VersionMinor) 30 31 if minorVersionCompare.IsNotEqualLogically() { 32 return minorVersionCompare 33 } 34 35 patchVersionCompare := corecmp.Integer( 36 left.VersionPatch, 37 right.VersionPatch, 38 ) 39 40 if patchVersionCompare.IsNotEqualLogically() { 41 return patchVersionCompare 42 } 43 44 return corecomparator.Equal 45 } 46 47 // CompareVersionString 48 // 49 // See New.Default for more details 50 func CompareVersionString( 51 leftVersion, 52 rightVersion string, 53 ) corecomparator.Compare { 54 left := New.Default(leftVersion) 55 right := New.Default(rightVersion) 56 57 return Compare(left, right) 58 } 59 60 // IsExpectedVersion 61 // 62 // See New.Default for more details 63 func IsExpectedVersion( 64 expectedCompare corecomparator.Compare, 65 leftVersion, 66 rightVersion string, 67 ) bool { 68 cmp := CompareVersionString( 69 leftVersion, rightVersion) 70 71 return cmp.IsCompareEqualLogically(expectedCompare) 72 } 73 74 // IsAtLeast 75 // 76 // returns true if left version is equal or greater than the right 77 func IsAtLeast( 78 leftGreaterOrEqual, 79 rightVersion string, 80 ) bool { 81 cmp := CompareVersionString( 82 leftGreaterOrEqual, rightVersion) 83 84 return cmp.IsLeftGreaterEqualLogically() 85 } 86 87 // IsLower 88 // 89 // returns true if left version is less than the right version 90 func IsLower( 91 leftGreaterOrEqual, 92 rightVersion string, 93 ) bool { 94 cmp := CompareVersionString( 95 leftGreaterOrEqual, rightVersion) 96 97 return cmp.IsLeftLess() 98 } 99 100 // IsLowerOrEqual 101 // 102 // returns true if left version is less or equal than the right version 103 func IsLowerOrEqual( 104 leftGreaterOrEqual, 105 rightVersion string, 106 ) bool { 107 cmp := CompareVersionString( 108 leftGreaterOrEqual, rightVersion) 109 110 return cmp.IsLeftLessEqualLogically() 111 }