1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
alarm
api
auth
build
common
algorithm
app
archive
attributes
banner
bus
cache
coder
compress
config
data
debug
file
flow/flow
git
http
images
json
list
logger
mapper
option
queue
random
result
scheduler
secret
server
ssh
stringutil
svc
system
tag
template
timer
tls
trie
version
version.go
watcher
xml
yaml
bit_flag.go
common.go
integer.go
dao
discovery
loader
mq
perf
plugins
request
rpc
sensitive
thrift
.gitignore
LICENSE
Makefile
README.md
doc.go
error.md
go.mod
go.sum
goutils.go
goutils_test.go
version.go
克隆/下载
version.go 908 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 3年前 . 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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.21.2

搜索帮助