From 08e3605fa377996a121aabdafa85d63afbb7e455 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 20 Nov 2023 15:50:18 -0800 Subject: [PATCH] just use 2 variables... --- http_logging.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/http_logging.go b/http_logging.go index 6e79699..beef0e1 100644 --- a/http_logging.go +++ b/http_logging.go @@ -83,18 +83,19 @@ func LogResponse[T *ResponseRecorder | *http.Response](r T, msg string, extraAtt if !Log(Info) { return } - var attr []KeyVal - switch v := any(r).(type) { + var status int + var size int64 + switch v := any(r).(type) { // go generics... case *ResponseRecorder: - attr = []KeyVal{ - Int("status", v.StatusCode), - Int64("size", v.ContentLength), - } + status = v.StatusCode + size = v.ContentLength case *http.Response: - attr = []KeyVal{ - Int("status", v.StatusCode), - Int64("size", v.ContentLength), - } + status = v.StatusCode + size = v.ContentLength + } + attr := []KeyVal{ + Int("status", status), + Int64("size", size), } attr = append(attr, extraAttributes...) S(Info, msg, attr...)