代码拉取完成,页面将自动刷新
package common
import (
"fmt"
"strconv"
"strings"
)
type Version struct {
version string
Major int
Minor int
Bugfix int
Meta string
}
// NewVersion expects a string in the format:
// major.minor.bugfix(-meta)
func NewVersion(version string) (*Version, error) {
v := Version{
version: version,
}
// Check for meta info
if strings.Contains(version, "-") {
tmp := strings.Split(version, "-")
version = tmp[0]
v.Meta = tmp[1]
}
versions := strings.Split(version, ".")
if len(versions) != 3 {
return nil, fmt.Errorf("Passed version is not semver: %s", version)
}
var err error
v.Major, err = strconv.Atoi(versions[0])
if err != nil {
return nil, fmt.Errorf("Could not convert major to integer: %s", versions[0])
}
v.Minor, err = strconv.Atoi(versions[1])
if err != nil {
return nil, fmt.Errorf("Could not convert minor to integer: %s", versions[1])
}
v.Bugfix, err = strconv.Atoi(versions[2])
if err != nil {
return nil, fmt.Errorf("Could not convert bugfix to integer: %s", versions[2])
}
return &v, nil
}
func (v *Version) IsMajor(major int) bool {
return major == v.Major
}
// LessThan returns true if v is strictly smaller than v1. When comparing, the major,
// minor and bugfix numbers are compared in order. The meta part is not taken into account.
func (v *Version) LessThan(v1 *Version) bool {
if v.Major < v1.Major {
return true
} else if v.Major == v1.Major {
if v.Minor < v1.Minor {
return true
} else if v.Minor == v1.Minor {
if v.Bugfix < v1.Bugfix {
return true
}
}
}
return false
}
func (v *Version) String() string {
return v.version
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。