Skip to content

Commit

Permalink
Added Option.Marshal to support Avro serialization (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit authored Sep 17, 2024
1 parent c91e53b commit 78c9cf5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{},
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 78c9cf5

Please sign in to comment.