Skip to content

Commit

Permalink
version
Browse files Browse the repository at this point in the history
  • Loading branch information
researchlab committed Jul 27, 2023
1 parent 40df30e commit bc95eb4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gdk

import (
"encoding/json"
"fmt"
"runtime"
)

// ldflags
var (
version string
gitBranch string
gitTag string
gitCommit string
gitTreeState string
buildDate string
)

// Info contains versioning information.
type Info struct {
Version string `json:"version"`
GitBranch string `json:"gitBranch"`
GitTag string `json:"gitTag"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}

// String returns info as a human-friendly version string.
func (info Info) String() string {
b, _ := json.MarshalIndent(info, "", "\t")
return string(b)
}

func Version() Info {
return Info{
Version: version,
GitBranch: gitBranch,
GitTag: gitTag,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

0 comments on commit bc95eb4

Please sign in to comment.