2018-01-05 22:18:00 +03:00
|
|
|
package nats
|
|
|
|
|
|
|
|
import (
|
2018-01-06 15:15:55 +03:00
|
|
|
"golang.org/x/net/context"
|
2018-01-06 15:10:43 +03:00
|
|
|
|
2018-01-05 22:18:00 +03:00
|
|
|
"github.com/micro/go-micro/broker"
|
|
|
|
"github.com/nats-io/nats"
|
|
|
|
)
|
|
|
|
|
2018-01-06 15:10:43 +03:00
|
|
|
type optionsKey struct{}
|
2018-01-05 22:18:00 +03:00
|
|
|
|
2018-01-06 15:10:43 +03:00
|
|
|
// Options allow to inject a nats.Options struct for configuring
|
2018-01-05 22:18:00 +03:00
|
|
|
// the nats connection
|
2018-01-06 15:10:43 +03:00
|
|
|
func Options(nopts nats.Options) broker.Option {
|
2018-01-05 22:18:00 +03:00
|
|
|
return func(o *broker.Options) {
|
2018-01-06 15:10:43 +03:00
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, optionsKey{}, nopts)
|
2018-01-05 22:18:00 +03:00
|
|
|
}
|
|
|
|
}
|