Skip to content

Commit 959a5ec

Browse files
committed
feat: make Fanout a no-op when len(handlers) == 1
Updates #41
1 parent 1ea1fac commit 959a5ec

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

multi.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type FanoutHandler struct {
2121
}
2222

2323
// Fanout creates a new FanoutHandler that distributes records to multiple slog.Handler instances.
24+
// If exactly one handler is provided, it returns that handler unmodified.
2425
// This function is the primary entry point for creating a multi-handler setup.
2526
//
2627
// Example usage:
@@ -39,6 +40,9 @@ type FanoutHandler struct {
3940
//
4041
// A slog.Handler that forwards all operations to the provided handlers
4142
func Fanout(handlers ...slog.Handler) slog.Handler {
43+
if len(handlers) == 1 {
44+
return handlers[0]
45+
}
4246
return &FanoutHandler{
4347
handlers: handlers,
4448
}

0 commit comments

Comments
 (0)