ugly fix for nil context

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-10-14 14:47:04 +03:00
parent 28190f9489
commit 553fc8b998

View File

@ -177,9 +177,11 @@ func (k *kBroker) Publish(topic string, msg *broker.Message, opts ...broker.Publ
return err return err
} }
kmsg := kafka.Message{Value: val} kmsg := kafka.Message{Value: val}
if options.Context != nil {
if key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 { if key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 {
kmsg.Key = key kmsg.Key = key
} }
}
k.Lock() k.Lock()
writer, ok := k.writers[topic] writer, ok := k.writers[topic]