1 Star 0 Fork 0

h79 / goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
version.go 908 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2022-07-01 00:23 . version
package version
import (
"gitee.com/h79/goutils/common/stringutil"
"strings"
)
type Version struct {
version string
major int
minor int
}
func Build(version string) Version {
v := strings.Split(version, ".")
var vInt []int
for _, val := range v {
vInt = append(vInt, stringutil.StringToInt(val))
}
major := 0
minor := 0
vLen := len(vInt)
if vLen == 1 {
major = vInt[0]
} else if vLen == 2 {
major = vInt[0]<<16 + vInt[1]
} else if vLen == 3 {
major = vInt[0]<<16 + vInt[1]
minor = vInt[2]
} else if vLen >= 4 {
major = vInt[0]<<16 + vInt[1]
minor = vInt[2]<<16 + vInt[3]
}
return Version{version: version, major: major, minor: minor}
}
func (v Version) Compare(that Version) int {
if v.major > that.major {
return 1
} else if v.major < that.major {
return -1
}
if v.minor > that.minor {
return 1
} else if v.minor < that.minor {
return -1
}
return 0
}
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.20.57

搜索帮助