From e9c4f04e51e8d0de87afeab03584ccec9bfbecec Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Mon, 13 Nov 2023 13:43:57 -0500 Subject: [PATCH] use Info struct to marshal --- internal/version/version.go | 16 ++++++++-------- server/server.go | 6 +----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/internal/version/version.go b/internal/version/version.go index cedfde5..e4b1c88 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -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 { diff --git a/server/server.go b/server/server.go index 277bf90..2e96839 100644 --- a/server/server.go +++ b/server/server.go @@ -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()