2022-09-12 17:25:34 +08:00
|
|
|
package version
|
2022-05-17 22:17:37 +08:00
|
|
|
|
2022-07-02 10:47:16 +08:00
|
|
|
import (
|
2023-01-07 13:58:42 +08:00
|
|
|
"fmt"
|
2022-07-02 10:47:16 +08:00
|
|
|
"strings"
|
2023-01-07 13:58:42 +08:00
|
|
|
|
|
|
|
"golang.org/x/mod/semver"
|
2022-07-02 10:47:16 +08:00
|
|
|
)
|
|
|
|
|
2022-05-17 22:17:37 +08:00
|
|
|
// Version is the service current released version.
|
2022-07-02 10:47:16 +08:00
|
|
|
// Semantic versioning: https://semver.org/
|
2024-07-23 22:11:53 +08:00
|
|
|
var Version = "0.22.4"
|
2022-07-02 10:47:16 +08:00
|
|
|
|
|
|
|
// DevVersion is the service current development version.
|
2024-07-23 22:11:53 +08:00
|
|
|
var DevVersion = "0.22.4"
|
2022-07-02 10:47:16 +08:00
|
|
|
|
|
|
|
func GetCurrentVersion(mode string) string {
|
2023-02-19 13:36:45 +08:00
|
|
|
if mode == "dev" || mode == "demo" {
|
2022-07-02 10:47:16 +08:00
|
|
|
return DevVersion
|
|
|
|
}
|
|
|
|
return Version
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMinorVersion(version string) string {
|
|
|
|
versionList := strings.Split(version, ".")
|
|
|
|
if len(versionList) < 3 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return versionList[0] + "." + versionList[1]
|
|
|
|
}
|
|
|
|
|
2023-02-25 20:48:38 +08:00
|
|
|
// IsVersionGreaterOrEqualThan returns true if version is greater than or equal to target.
|
2022-07-02 10:47:16 +08:00
|
|
|
func IsVersionGreaterOrEqualThan(version, target string) bool {
|
2023-01-07 13:58:42 +08:00
|
|
|
return semver.Compare(fmt.Sprintf("v%s", version), fmt.Sprintf("v%s", target)) > -1
|
2022-07-02 10:47:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsVersionGreaterThan returns true if version is greater than target.
|
|
|
|
func IsVersionGreaterThan(version, target string) bool {
|
2023-01-07 13:58:42 +08:00
|
|
|
return semver.Compare(fmt.Sprintf("v%s", version), fmt.Sprintf("v%s", target)) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
type SortVersion []string
|
|
|
|
|
|
|
|
func (s SortVersion) Len() int {
|
|
|
|
return len(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SortVersion) Swap(i, j int) {
|
|
|
|
s[i], s[j] = s[j], s[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SortVersion) Less(i, j int) bool {
|
|
|
|
v1 := fmt.Sprintf("v%s", s[i])
|
|
|
|
v2 := fmt.Sprintf("v%s", s[j])
|
|
|
|
return semver.Compare(v1, v2) == -1
|
2022-07-02 10:47:16 +08:00
|
|
|
}
|