From 4c1f29ba01cfaf09b579379dfb25d6f8d38e2a05 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 18 Oct 2023 15:19:01 +0300 Subject: [PATCH] add HTTPStatus helper --- core/logger/attrs.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/logger/attrs.go b/core/logger/attrs.go index 39e304a..6e802c8 100644 --- a/core/logger/attrs.go +++ b/core/logger/attrs.go @@ -1,6 +1,9 @@ package logger -import "log/slog" +import ( + "log/slog" + "net/http" +) const ( HandlerAttr = "handler" @@ -20,3 +23,7 @@ func ErrAttr(err any) slog.Attr { } return slog.Any(ErrorAttr, err) } + +func HTTPStatus(code int) (slog.Attr, slog.Attr) { + return slog.Int(HTTPStatusAttr, code), slog.String(HTTPStatusNameAttr, http.StatusText(code)) +}