Add store to options (#1600)

This commit is contained in:
Asim Aslam 2020-05-01 18:05:09 +01:00 committed by GitHub
parent 08a2de1ef5
commit b3915b6020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -118,6 +118,12 @@ func Server(s *server.Server) Option {
}
}
func Store(s *store.Store) Option {
return func(o *Options) {
o.Store = s
}
}
func Tracer(t *trace.Tracer) Option {
return func(o *Options) {
o.Tracer = t

View File

@ -15,6 +15,7 @@ import (
"github.com/micro/go-micro/v2/debug/trace"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v2/server"
"github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v2/transport"
)
@ -26,6 +27,7 @@ type Options struct {
Config config.Config
Client client.Client
Server server.Server
Store store.Store
Registry registry.Registry
Transport transport.Transport
Profile profile.Profile
@ -51,6 +53,7 @@ func newOptions(opts ...Option) Options {
Config: config.DefaultConfig,
Client: client.DefaultClient,
Server: server.DefaultServer,
Store: store.DefaultStore,
Registry: registry.DefaultRegistry,
Transport: transport.DefaultTransport,
Context: context.Background(),
@ -118,6 +121,13 @@ func Server(s server.Server) Option {
}
}
// Store sets the store to use
func Store(s store.Store) Option {
return func(o *Options) {
o.Store = s
}
}
// Registry sets the registry for the service
// and the underlying components
func Registry(r registry.Registry) Option {

View File

@ -102,6 +102,7 @@ func (s *service) Init(opts ...Option) {
cmd.Client(&s.opts.Client),
cmd.Config(&s.opts.Config),
cmd.Server(&s.opts.Server),
cmd.Store(&s.opts.Store),
cmd.Profile(&s.opts.Profile),
); err != nil {
logger.Fatal(err)