diff --git a/README.md b/README.md index 994c636e..2400cd48 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ An example server can be found in go-micro/template. - Discovery - Client/Server - Pub/Sub -- Key/Value store ### Planned - Metrics diff --git a/cmd/cmd.go b/cmd/cmd.go index 1a7b8be2..c4f812d1 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -12,7 +12,6 @@ import ( "github.com/myodc/go-micro/client" "github.com/myodc/go-micro/registry" "github.com/myodc/go-micro/server" - "github.com/myodc/go-micro/store" "github.com/myodc/go-micro/transport" // brokers @@ -23,12 +22,6 @@ import ( "github.com/myodc/go-micro/registry/consul" "github.com/myodc/go-micro/registry/kubernetes" - // stores - sconsul "github.com/myodc/go-micro/store/consul" - "github.com/myodc/go-micro/store/etcd" - "github.com/myodc/go-micro/store/memcached" - "github.com/myodc/go-micro/store/memory" - // transport thttp "github.com/myodc/go-micro/transport/http" tnats "github.com/myodc/go-micro/transport/nats" @@ -65,17 +58,6 @@ var ( EnvVar: "MICRO_REGISTRY_ADDRESS", Usage: "Comma-separated list of registry addresses", }, - cli.StringFlag{ - Name: "store", - EnvVar: "MICRO_STORE", - Value: "consul", - Usage: "Store used as a basic key/value store using consul, memcached, etc", - }, - cli.StringFlag{ - Name: "store_address", - EnvVar: "MICRO_STORE_ADDRESS", - Usage: "Comma-separated list of store addresses", - }, cli.StringFlag{ Name: "transport", EnvVar: "MICRO_TRANSPORT", @@ -111,19 +93,6 @@ func Setup(c *cli.Context) error { registry.DefaultRegistry = consul.NewRegistry(rAddrs) } - sAddrs := strings.Split(c.String("store_address"), ",") - - switch c.String("store") { - case "consul": - store.DefaultStore = sconsul.NewStore(sAddrs) - case "memcached": - store.DefaultStore = memcached.NewStore(sAddrs) - case "memory": - store.DefaultStore = memory.NewStore(sAddrs) - case "etcd": - store.DefaultStore = etcd.NewStore(sAddrs) - } - tAddrs := strings.Split(c.String("transport_address"), ",") switch c.String("transport") { diff --git a/store/consul/consul.go b/store/consul/consul.go deleted file mode 100644 index 4c103b17..00000000 --- a/store/consul/consul.go +++ /dev/null @@ -1,11 +0,0 @@ -package consul - -// This is a hack - -import ( - "github.com/myodc/go-micro/store" -) - -func NewStore(addrs []string, opt ...store.Option) store.Store { - return store.NewStore(addrs, opt...) -} diff --git a/store/consul_store.go b/store/consul_store.go deleted file mode 100644 index be79fbd5..00000000 --- a/store/consul_store.go +++ /dev/null @@ -1,53 +0,0 @@ -package store - -import ( - "errors" - - consul "github.com/hashicorp/consul/api" -) - -type consulStore struct { - Client *consul.Client -} - -func (c *consulStore) Get(key string) (*Item, error) { - kv, _, err := c.Client.KV().Get(key, nil) - if err != nil { - return nil, err - } - if kv == nil { - return nil, errors.New("key not found") - } - - return &Item{ - Key: kv.Key, - Value: kv.Value, - }, nil -} - -func (c *consulStore) Del(key string) error { - _, err := c.Client.KV().Delete(key, nil) - return err -} - -func (c *consulStore) Put(item *Item) error { - _, err := c.Client.KV().Put(&consul.KVPair{ - Key: item.Key, - Value: item.Value, - }, nil) - - return err -} - -func newConsulStore(addrs []string, opt ...Option) Store { - config := consul.DefaultConfig() - if len(addrs) > 0 { - config.Address = addrs[0] - } - - client, _ := consul.NewClient(config) - - return &consulStore{ - Client: client, - } -} diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go deleted file mode 100644 index 18cbd0c2..00000000 --- a/store/etcd/etcd.go +++ /dev/null @@ -1,50 +0,0 @@ -package etcd - -import ( - "errors" - - "github.com/coreos/go-etcd/etcd" - "github.com/myodc/go-micro/store" -) - -type estore struct { - Client *etcd.Client -} - -func (e *estore) Get(key string) (*store.Item, error) { - kv, err := e.Client.Get(key, false, false) - if err != nil { - return nil, err - } - if kv == nil { - return nil, errors.New("key not found") - } - - return &store.Item{ - Key: kv.Node.Key, - Value: []byte(kv.Node.Value), - }, nil -} - -func (e *estore) Del(key string) error { - _, err := e.Client.Delete(key, false) - return err -} - -func (e *estore) Put(item *store.Item) error { - _, err := e.Client.Set(item.Key, string(item.Value), 0) - - return err -} - -func NewStore(addrs []string, opts ...store.Option) store.Store { - if len(addrs) == 0 { - addrs = []string{"127.0.0.1:2379"} - } - - client := etcd.NewClient(addrs) - - return &estore{ - Client: client, - } -} diff --git a/store/memcached/memcached.go b/store/memcached/memcached.go deleted file mode 100644 index c7902717..00000000 --- a/store/memcached/memcached.go +++ /dev/null @@ -1,50 +0,0 @@ -package memcached - -import ( - "errors" - - mc "github.com/bradfitz/gomemcache/memcache" - "github.com/myodc/go-micro/store" -) - -type mstore struct { - Client *mc.Client -} - -func (m *mstore) Get(key string) (*store.Item, error) { - kv, err := m.Client.Get(key) - if err != nil && err == mc.ErrCacheMiss { - return nil, errors.New("key not found") - } else if err != nil { - return nil, err - } - - if kv == nil { - return nil, errors.New("key not found") - } - - return &store.Item{ - Key: kv.Key, - Value: kv.Value, - }, nil -} - -func (m *mstore) Del(key string) error { - return m.Client.Delete(key) -} - -func (m *mstore) Put(item *store.Item) error { - return m.Client.Set(&mc.Item{ - Key: item.Key, - Value: item.Value, - }) -} - -func NewStore(addrs []string, opts ...store.Option) store.Store { - if len(addrs) == 0 { - addrs = []string{"127.0.0.1:11211"} - } - return &mstore{ - Client: mc.New(addrs...), - } -} diff --git a/store/memory/memory.go b/store/memory/memory.go deleted file mode 100644 index d39585da..00000000 --- a/store/memory/memory.go +++ /dev/null @@ -1,43 +0,0 @@ -package memory - -import ( - "errors" - "sync" - - "github.com/myodc/go-micro/store" -) - -type mstore struct { - sync.RWMutex - store map[string]*store.Item -} - -func (m *mstore) Get(key string) (*store.Item, error) { - m.RLock() - v, ok := m.store[key] - m.RUnlock() - if !ok { - return nil, errors.New("key not found") - } - return v, nil -} - -func (m *mstore) Del(key string) error { - m.Lock() - delete(m.store, key) - m.Unlock() - return nil -} - -func (m *mstore) Put(item *store.Item) error { - m.Lock() - m.store[item.Key] = item - m.Unlock() - return nil -} - -func NewStore(addrs []string, opt ...store.Option) store.Store { - return &mstore{ - store: make(map[string]*store.Item), - } -} diff --git a/store/store.go b/store/store.go deleted file mode 100644 index 2caf0296..00000000 --- a/store/store.go +++ /dev/null @@ -1,36 +0,0 @@ -package store - -type Store interface { - Get(string) (*Item, error) - Del(string) error - Put(*Item) error -} - -type Item struct { - Key string - Value []byte -} - -type options struct{} - -type Option func(*options) - -var ( - DefaultStore = newConsulStore([]string{}) -) - -func NewStore(addrs []string, opt ...Option) Store { - return newConsulStore(addrs, opt...) -} - -func Get(key string) (*Item, error) { - return DefaultStore.Get(key) -} - -func Del(key string) error { - return DefaultStore.Del(key) -} - -func Put(item *Item) error { - return DefaultStore.Put(item) -}