add store to defaults (#1086)
This commit is contained in:
@@ -49,6 +49,14 @@ import (
|
||||
// runtimes
|
||||
"github.com/micro/go-micro/runtime"
|
||||
"github.com/micro/go-micro/runtime/kubernetes"
|
||||
|
||||
// stores
|
||||
"github.com/micro/go-micro/store"
|
||||
cfStore "github.com/micro/go-micro/store/cloudflare"
|
||||
ckStore "github.com/micro/go-micro/store/cockroach"
|
||||
etcdStore "github.com/micro/go-micro/store/etcd"
|
||||
memStore "github.com/micro/go-micro/store/memory"
|
||||
svcStore "github.com/micro/go-micro/store/service"
|
||||
)
|
||||
|
||||
type Cmd interface {
|
||||
@@ -239,6 +247,14 @@ var (
|
||||
"kubernetes": kubernetes.NewRuntime,
|
||||
}
|
||||
|
||||
DefaultStores = map[string]func(...store.Option) store.Store{
|
||||
"memory": memStore.NewStore,
|
||||
"cockroach": ckStore.NewStore,
|
||||
"etcd": etcdStore.NewStore,
|
||||
"cloudflare": cfStore.NewStore,
|
||||
"service": svcStore.NewStore,
|
||||
}
|
||||
|
||||
// used for default selection as the fall back
|
||||
defaultClient = "grpc"
|
||||
defaultServer = "grpc"
|
||||
@@ -267,6 +283,7 @@ func newCmd(opts ...Option) Cmd {
|
||||
Selector: &selector.DefaultSelector,
|
||||
Transport: &transport.DefaultTransport,
|
||||
Runtime: &runtime.DefaultRuntime,
|
||||
Store: &store.DefaultStore,
|
||||
|
||||
Brokers: DefaultBrokers,
|
||||
Clients: DefaultClients,
|
||||
@@ -275,6 +292,7 @@ func newCmd(opts ...Option) Cmd {
|
||||
Servers: DefaultServers,
|
||||
Transports: DefaultTransports,
|
||||
Runtimes: DefaultRuntimes,
|
||||
Stores: DefaultStores,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
@@ -315,6 +333,16 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
var serverOpts []server.Option
|
||||
var clientOpts []client.Option
|
||||
|
||||
// Set the runtime
|
||||
if name := ctx.String("store"); len(name) > 0 {
|
||||
s, ok := c.opts.Stores[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("Unsupported store: %s", name)
|
||||
}
|
||||
|
||||
*c.opts.Store = s()
|
||||
}
|
||||
|
||||
// Set the runtime
|
||||
if name := ctx.String("runtime"); len(name) > 0 {
|
||||
r, ok := c.opts.Runtimes[name]
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/micro/go-micro/registry"
|
||||
"github.com/micro/go-micro/runtime"
|
||||
"github.com/micro/go-micro/server"
|
||||
"github.com/micro/go-micro/store"
|
||||
"github.com/micro/go-micro/transport"
|
||||
)
|
||||
|
||||
@@ -26,6 +27,7 @@ type Options struct {
|
||||
Client *client.Client
|
||||
Server *server.Server
|
||||
Runtime *runtime.Runtime
|
||||
Store *store.Store
|
||||
|
||||
Brokers map[string]func(...broker.Option) broker.Broker
|
||||
Clients map[string]func(...client.Option) client.Client
|
||||
@@ -34,6 +36,7 @@ type Options struct {
|
||||
Servers map[string]func(...server.Option) server.Server
|
||||
Transports map[string]func(...transport.Option) transport.Transport
|
||||
Runtimes map[string]func(...runtime.Option) runtime.Runtime
|
||||
Stores map[string]func(...store.Option) store.Store
|
||||
|
||||
// Other options for implementations of the interface
|
||||
// can be stored in a context
|
||||
|
Reference in New Issue
Block a user