From b4aa04fa25204caa1ce74e3fa80c1877caf2aaee Mon Sep 17 00:00:00 2001 From: Cedric Paillet Date: Tue, 18 Jun 2024 09:54:57 +0200 Subject: [PATCH 1/2] fix(api): handle fmt.Fprintf error - Added error handling for fmt.Fprintf in healthCheck function - Added error handling for fmt.Fprintf in getVersion function done to avoid golangci-lint new error. --- internal/api/router/endpoints.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/api/router/endpoints.go b/internal/api/router/endpoints.go index 91b35cc..98d270a 100644 --- a/internal/api/router/endpoints.go +++ b/internal/api/router/endpoints.go @@ -19,12 +19,12 @@ const wildcard = "*" func healthCheck(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) { w.Header().Set(contentType, applicationJSON) - fmt.Fprintf(w, `{"status": "ok"}`) + _, _ = fmt.Fprintf(w, `{"status": "ok"}`) } func getVersion(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) { w.Header().Set(contentType, applicationJSON) - fmt.Fprintf(w, `{"version": "%s", "build_time": "%s", "build_user": "%s"}`, app.Info.Version, app.Info.BuildTime, app.Info.BuildUser) + _, _ = fmt.Fprintf(w, `{"version": "%s", "build_time": "%s", "build_user": "%s"}`, app.Info.Version, app.Info.BuildTime, app.Info.BuildUser) } func prometheusMetrics(h http.Handler) httprouter.Handle { From 2933a3a3294f7ac229ec91ad5490938ca550ff2e Mon Sep 17 00:00:00 2001 From: Cedric Paillet Date: Tue, 18 Jun 2024 09:42:05 +0200 Subject: [PATCH 2/2] fix(serializer): remove dead code This code is not used. --- internal/convertor/device/serializer.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/internal/convertor/device/serializer.go b/internal/convertor/device/serializer.go index 64592b8..32bab44 100644 --- a/internal/convertor/device/serializer.go +++ b/internal/convertor/device/serializer.go @@ -1,7 +1,6 @@ package device import ( - "bytes" "encoding/json" "errors" @@ -94,18 +93,12 @@ func (s *SafeRepository) GetDeviceOpenConfigJSON(hostname string) ([]byte, error var config json.RawMessage var err error - out := bytes.NewBuffer(nil) if config, err = dev.GetCompactJSON(); err != nil { log.Error().Err(err).Send() return []byte(emptyJSON), err } - if err := json.Compact(out, []byte(dev.Config.JSON)); err != nil { - log.Error().Err(err).Send() - return []byte(emptyJSON), err - } - if r, err := json.Marshal(config); err != nil { log.Error().Err(err).Send() return []byte(emptyJSON), err