【rich function】VersionCompare replace
This commit is contained in:
@@ -10,14 +10,15 @@ func Compare(v1, v2 string) int {
|
||||
replaceMap := map[string]string{"V": "", "v": "", "-": "."}
|
||||
for k, v := range replaceMap {
|
||||
if strings.Contains(v1, k) {
|
||||
strings.Replace(v1, k, v, -1)
|
||||
v1 = strings.Replace(v1, k, v, -1)
|
||||
}
|
||||
if strings.Contains(v2, k) {
|
||||
strings.Replace(v2, k, v, -1)
|
||||
v2 = strings.Replace(v2, k, v, -1)
|
||||
}
|
||||
}
|
||||
verStr1 := strings.Split(v1, ".")
|
||||
verStr2 := strings.Split(v2, ".")
|
||||
|
||||
ver1 := strSlice2IntSlice(verStr1)
|
||||
ver2 := strSlice2IntSlice(verStr2)
|
||||
|
||||
@@ -64,8 +65,8 @@ func strSlice2IntSlice(strs []string) []int64 {
|
||||
return retInt
|
||||
}
|
||||
|
||||
//operator compare returns true if the first field and the second field are equal else false
|
||||
func CompareVersions(v1, v2, operator string) bool {
|
||||
//operator compare returns true if the first field and the third field equation holds else false
|
||||
func CompareVersions(v1, operator, v2 string) bool {
|
||||
com := Compare(v1, v2)
|
||||
switch operator {
|
||||
case "==":
|
||||
|
||||
Reference in New Issue
Block a user