From 2d6163afd007512d9e7591406376012bf8d3e923 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 3 Dec 2019 02:23:42 +0300 Subject: [PATCH] provide setServerSubscriberOption to brokers Signed-off-by: Vasiliy Tolstov --- context.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/context.go b/context.go index 0f009e8..4388b9e 100644 --- a/context.go +++ b/context.go @@ -4,6 +4,7 @@ import ( "context" "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/server" ) // setSubscribeOption returns a function to setup a context with given value @@ -26,6 +27,16 @@ func setBrokerOption(k, v interface{}) broker.Option { } } +// setBrokerOption returns a function to setup a context with given value +func setServerSubscriberOption(k, v interface{}) server.SubscriberOption { + return func(o *server.SubscriberOptions) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +} + // setPublishOption returns a function to setup a context with given value func setPublishOption(k, v interface{}) broker.PublishOption { return func(o *broker.PublishOptions) {