From 022c90496a46b0a0423dd2cb1c02a3473ba5d224 Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Wed, 4 Sep 2024 19:32:35 +0300 Subject: [PATCH] stats: imp code --- internal/stats/http.go | 57 ++++++------------------------------------ 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/internal/stats/http.go b/internal/stats/http.go index a6789c65..7415e0db 100644 --- a/internal/stats/http.go +++ b/internal/stats/http.go @@ -72,13 +72,8 @@ func (s *StatsCtx) handleStats(w http.ResponseWriter, r *http.Request) { if !ok { // Don't bring the message to the lower case since it's a part of UI // text for the moment. - aghhttp.ErrorAndLog( - ctx, - s.logger, - r, - w, - http.StatusInternalServerError, "Couldn't get statistics data", - ) + const msg = "Couldn't get statistics data" + aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusInternalServerError, msg) return } @@ -162,28 +157,13 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) { reqData := configResp{} err := json.NewDecoder(r.Body).Decode(&reqData) if err != nil { - aghhttp.ErrorAndLog( - ctx, - s.logger, - r, - w, - http.StatusBadRequest, - "json decode: %s", - err, - ) + aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusBadRequest, "json decode: %s", err) return } if !checkInterval(reqData.IntervalDays) { - aghhttp.ErrorAndLog( - ctx, - s.logger, - r, - w, - http.StatusBadRequest, - "Unsupported interval", - ) + aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusBadRequest, "Unsupported interval") return } @@ -206,30 +186,14 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) reqData := getConfigResp{} err := json.NewDecoder(r.Body).Decode(&reqData) if err != nil { - aghhttp.ErrorAndLog( - ctx, - s.logger, - r, - w, - http.StatusBadRequest, - "json decode: %s", - err, - ) + aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusBadRequest, "json decode: %s", err) return } engine, err := aghnet.NewIgnoreEngine(reqData.Ignored) if err != nil { - aghhttp.ErrorAndLog( - ctx, - s.logger, - r, - w, - http.StatusUnprocessableEntity, - "ignored: %s", - err, - ) + aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusUnprocessableEntity, "ignored: %s", err) return } @@ -251,14 +215,7 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) } if reqData.Enabled == aghalg.NBNull { - aghhttp.ErrorAndLog( - ctx, - s.logger, - r, - w, - http.StatusUnprocessableEntity, - "enabled is null", - ) + aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusUnprocessableEntity, "enabled is null") return }