Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Option.Marshal to support Avro serialization #2

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading