2019-01-26 13:37:58 +03:00
|
|
|
package nats
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-01-31 01:26:39 +03:00
|
|
|
"github.com/micro/go-micro/v2/broker"
|
|
|
|
"github.com/micro/go-micro/v2/server"
|
2019-01-26 13:37:58 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// setSubscribeOption returns a function to setup a context with given value
|
|
|
|
func setSubscribeOption(k, v interface{}) broker.SubscribeOption {
|
|
|
|
return func(o *broker.SubscribeOptions) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// setBrokerOption returns a function to setup a context with given value
|
|
|
|
func setBrokerOption(k, v interface{}) broker.Option {
|
|
|
|
return func(o *broker.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 02:23:42 +03:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 13:37:58 +03:00
|
|
|
// setPublishOption returns a function to setup a context with given value
|
|
|
|
func setPublishOption(k, v interface{}) broker.PublishOption {
|
|
|
|
return func(o *broker.PublishOptions) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, k, v)
|
|
|
|
}
|
|
|
|
}
|