Skip to content

Commit

Permalink
Drop support for Go older than 1.18 (#612)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
SuperQ authored Mar 25, 2024
1 parent 95edf51 commit 3dec13c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 94 deletions.
49 changes: 49 additions & 0 deletions version/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"fmt"
"runtime"
"runtime/debug"
"strings"
"text/template"
)
Expand All @@ -31,6 +32,9 @@ var (
GoVersion = runtime.Version()
GoOS = runtime.GOOS
GoArch = runtime.GOARCH

computedRevision string
computedTags string
)

// versionInfoTmpl contains the template used by Info.
Expand Down Expand Up @@ -74,3 +78,48 @@ func Info() string {
func BuildContext() string {
return fmt.Sprintf("(go=%s, platform=%s, user=%s, date=%s, tags=%s)", GoVersion, GoOS+"/"+GoArch, BuildUser, BuildDate, GetTags())
}

func GetRevision() string {
if Revision != "" {
return Revision
}
return computedRevision
}

func GetTags() string {
return computedTags
}

func init() {
computedRevision, computedTags = computeRevision()
}

func computeRevision() (string, string) {
var (
rev = "unknown"
tags = "unknown"
modified bool
)

buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return rev, tags
}
for _, v := range buildInfo.Settings {
if v.Key == "vcs.revision" {
rev = v.Value
}
if v.Key == "vcs.modified" {
if v.Value == "true" {
modified = true
}
}
if v.Key == "-tags" {
tags = v.Value
}
}
if modified {
return rev + "-modified", tags
}
return rev, tags
}
25 changes: 0 additions & 25 deletions version/info_default.go

This file was deleted.

69 changes: 0 additions & 69 deletions version/info_go118.go

This file was deleted.

0 comments on commit 3dec13c

Please sign in to comment.