Line | |
---|
1 | package suika
|
---|
2 |
|
---|
3 | import (
|
---|
4 | "fmt"
|
---|
5 | "runtime/debug"
|
---|
6 | "strings"
|
---|
7 | )
|
---|
8 |
|
---|
9 | const (
|
---|
10 | defaultVersion = "0.0.0"
|
---|
11 | defaultBuild = "0000-01-01:00:00+00:00"
|
---|
12 | )
|
---|
13 |
|
---|
14 | var (
|
---|
15 | // Version is the tagged release version in the form <major>.<minor>.<patch>
|
---|
16 | // following semantic versioning and is overwritten by the build system.
|
---|
17 | Version = defaultVersion
|
---|
18 |
|
---|
19 | // Build is the date and time of the build as an RFC3339 formatted string
|
---|
20 | // and is overwritten by the build system.
|
---|
21 | Build = defaultBuild
|
---|
22 | )
|
---|
23 |
|
---|
24 | // FullVersion display the full version and build
|
---|
25 | func FullVersion() string {
|
---|
26 | var sb strings.Builder
|
---|
27 |
|
---|
28 | isDefault := Version == defaultVersion && Build == defaultBuild
|
---|
29 |
|
---|
30 | if !isDefault {
|
---|
31 | sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Build))
|
---|
32 | }
|
---|
33 |
|
---|
34 | if info, ok := debug.ReadBuildInfo(); ok {
|
---|
35 | if isDefault {
|
---|
36 | sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
|
---|
37 | }
|
---|
38 | sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
|
---|
39 | if info.Main.Sum != "" {
|
---|
40 | sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | return sb.String()
|
---|
45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.