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,8 +177,10 @@ 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 key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 { if options.Context != nil {
kmsg.Key = key if key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 {
kmsg.Key = key
}
} }
k.Lock() k.Lock()