Code maintenance: better JSON decoding for HTTP

This commit is contained in:
Quentin McGaw
2020-12-29 00:56:51 +00:00
parent 73479bab26
commit 8dd38fd182
3 changed files with 14 additions and 31 deletions

View File

@@ -50,13 +50,9 @@ func (h *handlerV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func (h *handlerV1) getVersion(w http.ResponseWriter) {
data, err := json.Marshal(h.buildInfo)
if err != nil {
encoder := json.NewEncoder(w)
if err := encoder.Encode(h.buildInfo); err != nil {
h.logger.Warn(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if _, err := w.Write(data); err != nil {
h.logger.Warn(err)
}
}