Merge pull request #75 from unistack-org/codec_body_only

fix noop codec usage and body only option
This commit is contained in:
Василий Толстов 2022-08-28 16:11:20 +03:00 committed by GitHub
commit 6ccc996fe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

6
kgo.go
View File

@ -264,13 +264,13 @@ func (k *kBroker) publish(ctx context.Context, msgs []*broker.Message, opts ...b
for _, msg := range msgs {
rec := &kgo.Record{Key: key}
rec.Topic, _ = msg.Header.Get(metadata.HeaderTopic)
if options.BodyOnly {
rec.Value = msg.Body
} else if k.opts.Codec.String() == "noop" {
if k.opts.Codec.String() == "noop" {
rec.Value = msg.Body
for k, v := range msg.Header {
rec.Headers = append(rec.Headers, kgo.RecordHeader{Key: k, Value: []byte(v)})
}
} else if options.BodyOnly {
rec.Value = msg.Body
} else {
rec.Value, err = k.opts.Codec.Marshal(msg)
if err != nil {