diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index c2dbd9a5..d2811dc6 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -278,6 +278,7 @@ var ( defaultSelector = "registry" defaultTransport = "http" defaultRuntime = "local" + defaultStore = "memory" ) func init() { diff --git a/defaults.go b/defaults.go index f1a81e7c..0159f19c 100644 --- a/defaults.go +++ b/defaults.go @@ -3,10 +3,12 @@ package micro import ( "github.com/micro/go-micro/client" "github.com/micro/go-micro/server" + "github.com/micro/go-micro/store" // set defaults gcli "github.com/micro/go-micro/client/grpc" gsrv "github.com/micro/go-micro/server/grpc" + memStore "github.com/micro/go-micro/store/memory" ) func init() { @@ -14,4 +16,6 @@ func init() { client.DefaultClient = gcli.NewClient() // default server server.DefaultServer = gsrv.NewServer() + // default store + store.DefaultStore = memStore.NewStore() } diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 9bc4b69f..ff1a6d8e 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -332,6 +332,10 @@ func (w *workersKV) request(ctx context.Context, method, path string, body inter return respBody, resp.Header, resp.StatusCode, nil } +func (w *workersKV) String() string { + return "cloudflare" +} + // New returns a cloudflare Store implementation. // Account ID, Token and Namespace must either be passed as options or // environment variables. If set as env vars we expect the following; diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 95fe34f4..bbfadf07 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -239,6 +239,10 @@ func (s *sqlStore) configure() error { return s.initDB() } +func (s *sqlStore) String() string { + return "cockroach" +} + // New returns a new micro Store backed by sql func NewStore(opts ...store.Option) store.Store { var options store.Options @@ -248,6 +252,8 @@ func NewStore(opts ...store.Option) store.Store { // new store s := new(sqlStore) + // set the options + s.options = options // configure the store if err := s.configure(); err != nil { diff --git a/store/memory/memory.go b/store/memory/memory.go index 814a7459..224c0f97 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -130,6 +130,10 @@ func (m *memoryStore) Delete(key string) error { return nil } +func (m *memoryStore) String() string { + return "memory" +} + // NewStore returns a new store.Store func NewStore(opts ...store.Option) store.Store { var options store.Options diff --git a/store/service/service.go b/store/service/service.go index 8610541b..6a34bdfe 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -137,6 +137,10 @@ func (s *serviceStore) Delete(key string) error { return err } +func (s *serviceStore) String() string { + return "service" +} + // NewStore returns a new store service implementation func NewStore(opts ...store.Option) store.Store { var options store.Options diff --git a/store/store.go b/store/store.go index c84e76cb..2e7d73ca 100644 --- a/store/store.go +++ b/store/store.go @@ -25,6 +25,8 @@ type Store interface { Write(*Record) error // Delete records with keys Delete(key string) error + // Name of the store + String() string } // Record represents a data record @@ -62,3 +64,7 @@ func (n *noop) Write(rec *Record) error { func (n *noop) Delete(key string) error { return nil } + +func (n *noop) String() string { + return "noop" +}