Skip to content

Commit

Permalink
use Info struct to marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoile committed Nov 13, 2023
1 parent 3d4b609 commit e9c4f04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 8 additions & 8 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func GetVersion() error {
}

type Info struct {
GitVersion string
BuildHash string
BuildVersion string
GitTreeState string
BuildDate string
GoVersion string
Compiler string
Platform string
GitVersion string `json:"-"`
BuildHash string `json:"hash"`
BuildVersion string `json:"version"`
GitTreeState string `json:"-"`
BuildDate string `json:"-"`
GoVersion string `json:"-"`
Compiler string `json:"-"`
Platform string `json:"-"`
}

func VersionInfo() Info {
Expand Down
6 changes: 1 addition & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,9 @@ func root(w http.ResponseWriter, r *http.Request) {

func (s *Server) version(w http.ResponseWriter, _ *http.Request) {
info := version.VersionInfo()
ret := map[string]interface{}{
"version": info.BuildVersion,
"hash": info.BuildHash,
}

w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(ret); err != nil {
if err := json.NewEncoder(w).Encode(info); err != nil {
s.logger.Errorf("Failed to write response: %v", err)
if s.metrics != nil {
s.metrics.incrementBadRequest()
Expand Down

0 comments on commit e9c4f04

Please sign in to comment.