set default store, fix store options bug, add String method

This commit is contained in:
Asim Aslam 2020-01-10 19:13:55 +00:00
parent 37d1139a57
commit 6ca298c61d
7 changed files with 29 additions and 0 deletions

View File

@ -278,6 +278,7 @@ var (
defaultSelector = "registry"
defaultTransport = "http"
defaultRuntime = "local"
defaultStore = "memory"
)
func init() {

View File

@ -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()
}

View File

@ -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;

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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"
}