Skip to content

Commit 5523bc0

Browse files
authored
feat: add json output for version (#706)
1 parent 629641a commit 5523bc0

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

internal/core/build_info.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package core
22

33
import (
4+
"encoding/json"
45
"io/ioutil"
56
"net/http"
67
"os"
@@ -14,13 +15,23 @@ import (
1415
)
1516

1617
type BuildInfo struct {
17-
Version *version.Version
18-
BuildDate string
19-
GoVersion string
20-
GitBranch string
21-
GitCommit string
22-
GoArch string
23-
GoOS string
18+
Version *version.Version `json:"-"`
19+
BuildDate string `json:"build_date"`
20+
GoVersion string `json:"go_version"`
21+
GitBranch string `json:"git_branch"`
22+
GitCommit string `json:"git_commit"`
23+
GoArch string `json:"go_arch"`
24+
GoOS string `json:"go_os"`
25+
}
26+
27+
func (b *BuildInfo) MarshalJSON() ([]byte, error) {
28+
type Tmp BuildInfo
29+
return json.Marshal(
30+
struct {
31+
Tmp
32+
Version string `json:"version"`
33+
}{Tmp(*b), b.Version.String()},
34+
)
2435
}
2536

2637
const (

0 commit comments

Comments
 (0)