2022-05-17 17:17:37 +03:00
|
|
|
package common
|
|
|
|
|
2022-07-02 05:47:16 +03:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-05-17 17:17:37 +03:00
|
|
|
// Version is the service current released version.
|
2022-07-02 05:47:16 +03:00
|
|
|
// Semantic versioning: https://semver.org/
|
2022-07-29 16:09:48 +03:00
|
|
|
var Version = "0.3.0"
|
2022-07-02 05:47:16 +03:00
|
|
|
|
|
|
|
// DevVersion is the service current development version.
|
2022-07-24 16:01:56 +03:00
|
|
|
var DevVersion = "0.3.0"
|
2022-07-02 05:47:16 +03:00
|
|
|
|
|
|
|
func GetCurrentVersion(mode string) string {
|
|
|
|
if mode == "dev" {
|
|
|
|
return DevVersion
|
|
|
|
}
|
|
|
|
return Version
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMinorVersion(version string) string {
|
|
|
|
versionList := strings.Split(version, ".")
|
|
|
|
if len(versionList) < 3 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return versionList[0] + "." + versionList[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
// convSemanticVersionToInt converts version string to int.
|
|
|
|
func convSemanticVersionToInt(version string) int {
|
|
|
|
versionList := strings.Split(version, ".")
|
|
|
|
|
|
|
|
if len(versionList) < 3 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
major, err := strconv.Atoi(versionList[0])
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
minor, err := strconv.Atoi(versionList[1])
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
patch, err := strconv.Atoi(versionList[2])
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return major*10000 + minor*100 + patch
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsVersionGreaterThanOrEqualTo returns true if version is greater than or equal to target.
|
|
|
|
func IsVersionGreaterOrEqualThan(version, target string) bool {
|
|
|
|
return convSemanticVersionToInt(version) >= convSemanticVersionToInt(target)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsVersionGreaterThan returns true if version is greater than target.
|
|
|
|
func IsVersionGreaterThan(version, target string) bool {
|
|
|
|
return convSemanticVersionToInt(version) > convSemanticVersionToInt(target)
|
|
|
|
}
|