func TestCompareVerions(t *testing.T) {
fmt.Println(CompareVersions("1.1.0.1", "1.1.0"))
}
// v1<v2 return -1, v1>v2 return 1, v1==v2 return 0
func CompareVersions(v1 string, v2 string) int {
v1Arr := strings.Split(v1, ".")
v2Arr := strings.Split(v2, ".")
for i := 0; i < len(v1Arr) || i < len(v2Arr); i++ {
ver1, ver2 := 0, 0
if i < len(v1Arr) {
ver1, _ = strconv.Atoi(v1Arr[i])
}
if i < len(v2Arr) {
ver2, _ = strconv.Atoi(v2Arr[i])
}
if ver1 < ver2 {
return -1
} else if ver1 > ver2 {
return 1
}
}
return 0
}