generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
version.go
42 lines (34 loc) · 1.12 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ftl
import (
"fmt"
"regexp"
"strconv"
"time"
"github.com/alecthomas/types/must"
"golang.org/x/mod/semver"
)
// IsRelease returns true if the version is a release version.
func IsRelease(v string) bool {
return regexp.MustCompile(`^\d+\.\d+\.\d+$`).MatchString(v)
}
// IsVersionAtLeastMin returns true if any of the following are true:
// - minVersion is not defined (i.e. is emptystring)
// - v or minVersion is not a release version
// - v > minVersion when both v and minVersion are release versions
func IsVersionAtLeastMin(v string, minVersion string) bool {
if minVersion == "" {
return true
}
if !IsRelease(v) || !IsRelease(minVersion) {
return true
}
return semver.Compare("v"+v, "v"+minVersion) >= 0
}
// Version of FTL binary (set by linker).
var Version = "dev"
// FormattedVersion includes the version and timestamp.
var FormattedVersion = fmt.Sprintf("%s (%s)", Version, Timestamp.Format("2006-01-02"))
// Timestamp of FTL binary (set by linker).
var timestamp = "0"
// Timestamp parsed from timestamp (set by linker).
var Timestamp = time.Unix(0, must.Get(strconv.ParseInt(timestamp, 0, 64)))