diff --git a/aliases.go b/aliases.go index 89416580..554c9660 100644 --- a/aliases.go +++ b/aliases.go @@ -16,8 +16,10 @@ import ( var ( // BuildRevision holds the vcs commit id information. + // Available at go version 1.18+ BuildRevision = context.BuildRevision // BuildTime holds the vcs commit time information. + // Available at go version 1.18+ BuildTime = context.BuildTime ) diff --git a/context/context.go b/context/context.go index 91120e58..ef7d99f9 100644 --- a/context/context.go +++ b/context/context.go @@ -19,7 +19,6 @@ import ( "path/filepath" "reflect" "regexp" - "runtime/debug" "sort" "strconv" "strings" @@ -48,29 +47,13 @@ import ( var ( // BuildRevision holds the vcs commit id information. + // Available at go version 1.18+ BuildRevision string // BuildTime holds the vcs commit time information. + // Available at go version 1.18+ 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 ( // BodyDecoder is an interface which any struct can implement in order to customize the decode action // from ReadJSON and ReadXML diff --git a/context/context_go118.go b/context/context_go118.go new file mode 100644 index 00000000..b1773520 --- /dev/null +++ b/context/context_go118.go @@ -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 + } + } + } +}