micro-broker-nats/options.go

21 lines
376 B
Go
Raw Normal View History

2018-01-05 22:18:00 +03:00
package nats
import (
2018-03-03 15:28:44 +03:00
"context"
2018-01-05 22:18:00 +03:00
"github.com/micro/go-micro/broker"
"github.com/nats-io/go-nats"
2018-01-05 22:18:00 +03:00
)
type optionsKey struct{}
2018-01-05 22:18:00 +03:00
2018-01-06 18:19:15 +03:00
// Options accepts nats.Options
func Options(opts 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()
}
2018-01-06 18:19:15 +03:00
o.Context = context.WithValue(o.Context, optionsKey{}, opts)
2018-01-05 22:18:00 +03:00
}
}