Allow configurable addresses for everything
This commit is contained in:
@@ -46,8 +46,13 @@ func (c *ConsulStore) NewItem(key string, value []byte) Item {
|
||||
}
|
||||
}
|
||||
|
||||
func NewConsulStore() Store {
|
||||
client, _ := consul.NewClient(consul.DefaultConfig())
|
||||
func NewConsulStore(addrs []string, opts ...Options) Store {
|
||||
config := consul.DefaultConfig()
|
||||
if len(addrs) > 0 {
|
||||
config.Address = addrs[0]
|
||||
}
|
||||
|
||||
client, _ := consul.NewClient(config)
|
||||
|
||||
return &ConsulStore{
|
||||
Client: client,
|
||||
|
||||
@@ -43,8 +43,12 @@ func (e *EtcdStore) NewItem(key string, value []byte) Item {
|
||||
}
|
||||
}
|
||||
|
||||
func NewEtcdStore() Store {
|
||||
client := etcd.NewClient([]string{})
|
||||
func NewEtcdStore(addrs []string, opts ...Options) Store {
|
||||
if len(addrs) == 0 {
|
||||
addrs = []string{"127.0.0.1:2379"}
|
||||
}
|
||||
|
||||
client := etcd.NewClient(addrs)
|
||||
|
||||
return &EtcdStore{
|
||||
Client: client,
|
||||
|
||||
@@ -2,7 +2,6 @@ package store
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
mc "github.com/bradfitz/gomemcache/memcache"
|
||||
)
|
||||
@@ -47,19 +46,11 @@ func (m *MemcacheStore) NewItem(key string, value []byte) Item {
|
||||
}
|
||||
}
|
||||
|
||||
func NewMemcacheStore() Store {
|
||||
server := os.Getenv("MEMCACHED_SERVICE_HOST")
|
||||
port := os.Getenv("MEMCACHED_SERVICE_PORT")
|
||||
|
||||
if len(server) == 0 {
|
||||
server = "127.0.0.1"
|
||||
func NewMemcacheStore(addrs []string, opts ...Options) Store {
|
||||
if len(addrs) == 0 {
|
||||
addrs = []string{"127.0.0.1:11211"}
|
||||
}
|
||||
|
||||
if len(port) == 0 {
|
||||
port = "11211"
|
||||
}
|
||||
|
||||
return &MemcacheStore{
|
||||
Client: mc.New(server + ":" + port),
|
||||
Client: mc.New(addrs...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (m *MemoryStore) NewItem(key string, value []byte) Item {
|
||||
}
|
||||
}
|
||||
|
||||
func NewMemoryStore() Store {
|
||||
func NewMemoryStore(addrs []string, opts ...Options) Store {
|
||||
return &MemoryStore{
|
||||
store: make(map[string]Item),
|
||||
}
|
||||
|
||||
@@ -7,8 +7,12 @@ type Store interface {
|
||||
NewItem(string, []byte) Item
|
||||
}
|
||||
|
||||
type options struct{}
|
||||
|
||||
type Options func(*options)
|
||||
|
||||
var (
|
||||
DefaultStore = NewConsulStore()
|
||||
DefaultStore = NewConsulStore([]string{})
|
||||
)
|
||||
|
||||
func Get(key string) (Item, error) {
|
||||
|
||||
Reference in New Issue
Block a user