...
1
19
20 package version
21
22 import (
23 "fmt"
24 "runtime"
25
26 "bytes"
27 "encoding/json"
28 )
29
30 func Get() Info {
31 return Info{
32 GitVersion: gitVersion,
33 GitCommit: gitCommit,
34 GitTreeState: gitTreeState,
35 BuildDate: buildDate,
36 GoVersion: runtime.Version(),
37 Compiler: runtime.Compiler,
38 Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
39 }
40 }
41
42 func GetCompactJSON() (string, error) {
43 v, err := json.Marshal(Get())
44 if err != nil {
45 return "", err
46 }
47 compactedBuffer := new(bytes.Buffer)
48 err = json.Compact(compactedBuffer, []byte(v))
49 if err != nil {
50 return "", err
51 }
52 return compactedBuffer.String(), nil
53 }
54
View as plain text