Skip to content

Commit 3dec13c

Browse files
authored
Drop support for Go older than 1.18 (#612)
We don't support Go older than 1.21 in the Go modules file, so we can drop the special handling for older Go in the version package. Signed-off-by: SuperQ <superq@gmail.com>
1 parent 95edf51 commit 3dec13c

File tree

3 files changed

+49
-94
lines changed

3 files changed

+49
-94
lines changed

version/info.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"bytes"
1818
"fmt"
1919
"runtime"
20+
"runtime/debug"
2021
"strings"
2122
"text/template"
2223
)
@@ -31,6 +32,9 @@ var (
3132
GoVersion = runtime.Version()
3233
GoOS = runtime.GOOS
3334
GoArch = runtime.GOARCH
35+
36+
computedRevision string
37+
computedTags string
3438
)
3539

3640
// versionInfoTmpl contains the template used by Info.
@@ -74,3 +78,48 @@ func Info() string {
7478
func BuildContext() string {
7579
return fmt.Sprintf("(go=%s, platform=%s, user=%s, date=%s, tags=%s)", GoVersion, GoOS+"/"+GoArch, BuildUser, BuildDate, GetTags())
7680
}
81+
82+
func GetRevision() string {
83+
if Revision != "" {
84+
return Revision
85+
}
86+
return computedRevision
87+
}
88+
89+
func GetTags() string {
90+
return computedTags
91+
}
92+
93+
func init() {
94+
computedRevision, computedTags = computeRevision()
95+
}
96+
97+
func computeRevision() (string, string) {
98+
var (
99+
rev = "unknown"
100+
tags = "unknown"
101+
modified bool
102+
)
103+
104+
buildInfo, ok := debug.ReadBuildInfo()
105+
if !ok {
106+
return rev, tags
107+
}
108+
for _, v := range buildInfo.Settings {
109+
if v.Key == "vcs.revision" {
110+
rev = v.Value
111+
}
112+
if v.Key == "vcs.modified" {
113+
if v.Value == "true" {
114+
modified = true
115+
}
116+
}
117+
if v.Key == "-tags" {
118+
tags = v.Value
119+
}
120+
}
121+
if modified {
122+
return rev + "-modified", tags
123+
}
124+
return rev, tags
125+
}

version/info_default.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

version/info_go118.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)