From 78c9cf5dca8ca927883cdda7c477869d9081ca4d Mon Sep 17 00:00:00 2001 From: nicfit Date: Tue, 17 Sep 2024 10:26:31 -0600 Subject: [PATCH] Added Option.Marshal to support Avro serialization (#2) --- handler.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/handler.go b/handler.go index a5eaeb3..4305a09 100644 --- a/handler.go +++ b/handler.go @@ -27,6 +27,8 @@ type Option struct { // optional: see slog.HandlerOptions AddSource bool ReplaceAttr func(groups []string, a slog.Attr) slog.Attr + + Marshal func(v any) ([]byte, error) } func (o Option) NewKafkaHandler() slog.Handler { @@ -50,6 +52,10 @@ func (o Option) NewKafkaHandler() slog.Handler { o.AttrFromContext = []func(ctx context.Context) []slog.Attr{} } + if o.Marshal == nil { + o.Marshal = json.Marshal + } + return &KafkaHandler{ option: o, attrs: []slog.Attr{}, @@ -104,7 +110,7 @@ func (h *KafkaHandler) publish(timestamp time.Time, payload map[string]interface } // bearer:disable go_lang_deserialization_of_user_input - values, err := json.Marshal(payload) + values, err := h.option.Marshal(payload) if err != nil { return err }