micro-broker-nats/options.go

22 lines
448 B
Go
Raw Normal View History

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