This commit is contained in:
Gerasimos (Makis) Maropoulos 2022-04-10 01:11:11 +03:00
parent b0ccd579af
commit 193de00426
No known key found for this signature in database
GPG Key ID: 66FCC29BD385FCA6
3 changed files with 27 additions and 19 deletions

View File

@ -16,8 +16,10 @@ import (
var ( var (
// BuildRevision holds the vcs commit id information. // BuildRevision holds the vcs commit id information.
// Available at go version 1.18+
BuildRevision = context.BuildRevision BuildRevision = context.BuildRevision
// BuildTime holds the vcs commit time information. // BuildTime holds the vcs commit time information.
// Available at go version 1.18+
BuildTime = context.BuildTime BuildTime = context.BuildTime
) )

View File

@ -19,7 +19,6 @@ import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"regexp" "regexp"
"runtime/debug"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -48,29 +47,13 @@ import (
var ( var (
// BuildRevision holds the vcs commit id information. // BuildRevision holds the vcs commit id information.
// Available at go version 1.18+
BuildRevision string BuildRevision string
// BuildTime holds the vcs commit time information. // BuildTime holds the vcs commit time information.
// Available at go version 1.18+
BuildTime string BuildTime string
) )
func init() {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if BuildRevision != "" && BuildTime != "" {
break
}
if setting.Key == "vcs.revision" {
BuildRevision = setting.Value
}
if setting.Key == "vcs.time" {
BuildTime = setting.Key
}
}
}
}
type ( type (
// BodyDecoder is an interface which any struct can implement in order to customize the decode action // BodyDecoder is an interface which any struct can implement in order to customize the decode action
// from ReadJSON and ReadXML // from ReadJSON and ReadXML

23
context/context_go118.go Normal file
View File

@ -0,0 +1,23 @@
//go:build go1.18
package context
import "runtime/debug"
func init() {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if BuildRevision != "" && BuildTime != "" {
break
}
if setting.Key == "vcs.revision" {
BuildRevision = setting.Value
}
if setting.Key == "vcs.time" {
BuildTime = setting.Key
}
}
}
}