simplify TerminalHandler constructor/WithAttrs by omitting explicit instantiation for value types that take defaults

This commit is contained in:
Jared Wasinger 2023-11-15 16:57:35 +08:00
parent cdde508ef1
commit a86ccc4212

View file

@ -100,12 +100,10 @@ func NewTerminalHandler(wr io.Writer, useColor bool) *TerminalHandler {
// records which are less than or equal to the specified verbosity level. // records which are less than or equal to the specified verbosity level.
func NewTerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) *TerminalHandler { func NewTerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) *TerminalHandler {
return &TerminalHandler{ return &TerminalHandler{
sync.Mutex{}, wr: wr,
wr, lvl: lvl,
lvl, useColor: useColor,
useColor, fieldPadding: make(map[string]int),
[]slog.Attr{},
make(map[string]int),
} }
} }
@ -126,12 +124,11 @@ func (h *TerminalHandler) WithGroup(name string) slog.Handler {
func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler { func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return &TerminalHandler{ return &TerminalHandler{
sync.Mutex{}, wr: h.wr,
h.wr, lvl: h.lvl,
h.lvl, useColor: h.useColor,
h.useColor, attrs: append(h.attrs, attrs...),
append(h.attrs, attrs...), fieldPadding: make(map[string]int),
make(map[string]int),
} }
} }