From 4c4fa00a5d94f4301f5b48e063b76bb7b4da0fa0 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 22 Sep 2020 13:33:57 +0300 Subject: [PATCH] add useful func Signed-off-by: Vasiliy Tolstov --- server/context.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/context.go b/server/context.go index fa9f3c8b..daa70554 100644 --- a/server/context.go +++ b/server/context.go @@ -15,8 +15,18 @@ func NewContext(ctx context.Context, s Server) context.Context { return context.WithValue(ctx, serverKey{}, s) } -// SetServerSubscriberOption returns a function to setup a context with given value -func SetServerSubscriberOption(k, v interface{}) SubscriberOption { +// Setoption returns a function to setup a context with given value +func SetOption(k, v interface{}) Option { + return func(o *Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +} + +// SetSubscriberOption returns a function to setup a context with given value +func SetSubscriberOption(k, v interface{}) SubscriberOption { return func(o *SubscriberOptions) { if o.Context == nil { o.Context = context.Background()