all: imp code

This commit is contained in:
Stanislav Chzhen 2024-09-04 19:10:36 +03:00
parent 363a16f6bb
commit bb3c0c8002
2 changed files with 1 additions and 12 deletions

View File

@ -47,7 +47,6 @@ func Error(r *http.Request, w http.ResponseWriter, code int, format string, args
func ErrorAndLog( func ErrorAndLog(
ctx context.Context, ctx context.Context,
l *slog.Logger, l *slog.Logger,
lvl slog.Level,
r *http.Request, r *http.Request,
w http.ResponseWriter, w http.ResponseWriter,
code int, code int,
@ -55,9 +54,8 @@ func ErrorAndLog(
args ...any, args ...any,
) { ) {
text := fmt.Sprintf(format, args...) text := fmt.Sprintf(format, args...)
l.Log( l.ErrorContext(
ctx, ctx,
lvl,
"http error", "http error",
"method", r.Method, "method", r.Method,
"host", r.Host, "host", r.Host,

View File

@ -4,7 +4,6 @@ package stats
import ( import (
"encoding/json" "encoding/json"
"log/slog"
"net/http" "net/http"
"time" "time"
@ -76,7 +75,6 @@ func (s *StatsCtx) handleStats(w http.ResponseWriter, r *http.Request) {
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
ctx, ctx,
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusInternalServerError, "Couldn't get statistics data", http.StatusInternalServerError, "Couldn't get statistics data",
@ -167,7 +165,6 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
ctx, ctx,
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusBadRequest, http.StatusBadRequest,
@ -182,7 +179,6 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
ctx, ctx,
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusBadRequest, http.StatusBadRequest,
@ -213,7 +209,6 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
ctx, ctx,
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusBadRequest, http.StatusBadRequest,
@ -229,7 +224,6 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
ctx, ctx,
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusUnprocessableEntity, http.StatusUnprocessableEntity,
@ -246,7 +240,6 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
ctx, ctx,
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusUnprocessableEntity, http.StatusUnprocessableEntity,
@ -261,7 +254,6 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
ctx, ctx,
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusUnprocessableEntity, http.StatusUnprocessableEntity,
@ -288,7 +280,6 @@ func (s *StatsCtx) handleStatsReset(w http.ResponseWriter, r *http.Request) {
aghhttp.ErrorAndLog( aghhttp.ErrorAndLog(
r.Context(), r.Context(),
s.logger, s.logger,
slog.LevelError,
r, r,
w, w,
http.StatusInternalServerError, http.StatusInternalServerError,