From f39d31f8204eacc5d3b6b9037f0860471cefab86 Mon Sep 17 00:00:00 2001 From: Luka Zakrajsek Date: Thu, 3 Oct 2024 21:51:33 +0200 Subject: [PATCH] Add Clone to Event --- event.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/event.go b/event.go index b3eb7f6..b932564 100644 --- a/event.go +++ b/event.go @@ -3,6 +3,7 @@ package events import ( "fmt" "log/slog" + "maps" "sync" "github.com/google/uuid" @@ -45,6 +46,17 @@ func NewEvent(logger *slog.Logger) *Event { return e } +func (e *Event) Clone() *Event { + e.mutex.RLock() + attrs := maps.Clone(e.attrs) + e.mutex.RUnlock() + + return &Event{ + attrs: attrs, + baseLogger: e.baseLogger, + } +} + func (e *Event) SetAttr(key string, value any) { e.mutex.Lock() e.attrs[key] = slog.AnyValue(value)