From e18ca9aac110ecbafea66492daa03b15ea9ec9dc Mon Sep 17 00:00:00 2001 From: sunwei <18801147024@163.com> Date: Sun, 9 Aug 2020 22:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90rich=20function=E3=80=91VersionCompare?= =?UTF-8?q?=20replace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/utils/version.go | 35 ++--------------------------------- core/utils/version_test.go | 25 +------------------------ 2 files changed, 3 insertions(+), 57 deletions(-) diff --git a/core/utils/version.go b/core/utils/version.go index 656ac3358..bcd35667e 100644 --- a/core/utils/version.go +++ b/core/utils/version.go @@ -5,37 +5,6 @@ import ( "strings" ) -// returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower. -func CompareVersions(a, b string) int { - as := strings.Split(a, ".") - bs := strings.Split(b, ".") - var loop int - if len(as) > len(bs) { - loop = len(as) - } else { - loop = len(bs) - } - - for i := 0; i < loop; i++ { - var x, y string - if len(as) > i { - x = as[i] - } - if len(bs) > i { - y = bs[i] - } - xi, _ := strconv.Atoi(x) - yi, _ := strconv.Atoi(y) - if xi > yi { - return 1 - } else if xi < yi { - return -1 - } - } - - return 0 -} - //return 0 if they are equal,and 1 if v1>2,and 2 if v1