From b3915b602067ea07375902b98c0a4b31b7122ea7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 May 2020 18:05:09 +0100 Subject: [PATCH] Add store to options (#1600) --- config/cmd/options.go | 6 ++++++ options.go | 10 ++++++++++ service.go | 1 + 3 files changed, 17 insertions(+) diff --git a/config/cmd/options.go b/config/cmd/options.go index d105ee2e..7ec9e2b4 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -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 diff --git a/options.go b/options.go index 1ef8b955..d216b53e 100644 --- a/options.go +++ b/options.go @@ -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 { diff --git a/service.go b/service.go index f7941e30..e8115d29 100644 --- a/service.go +++ b/service.go @@ -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)