From 553fc8b998910ec4424937b3eecc07e84356e25f Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 14 Oct 2020 14:47:04 +0300 Subject: [PATCH] ugly fix for nil context Signed-off-by: Vasiliy Tolstov --- segmentio.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/segmentio.go b/segmentio.go index a1e8ae9..261fac6 100644 --- a/segmentio.go +++ b/segmentio.go @@ -177,8 +177,10 @@ func (k *kBroker) Publish(topic string, msg *broker.Message, opts ...broker.Publ return err } kmsg := kafka.Message{Value: val} - if key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 { - kmsg.Key = key + if options.Context != nil { + if key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 { + kmsg.Key = key + } } k.Lock()