-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40df30e
commit bc95eb4
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |