Skip to content

Commit

Permalink
Drop support for Go older than 1.18
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 <superq@gmail.com>
  • Loading branch information
SuperQ committed Mar 24, 2024
1 parent 617b51d commit a222ac5
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
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 a222ac5

Please sign in to comment.