Skip to content

Commit

Permalink
Merge 2cb6e76 into 20861cd
Browse files Browse the repository at this point in the history
  • Loading branch information
kmulvey committed May 19, 2019
2 parents 20861cd + 2cb6e76 commit bf27888
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion valkeyrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"sort"
"strings"
"sync"

"github.com/abronan/valkeyrie/store"
)
Expand All @@ -13,7 +14,8 @@ type Initialize func(addrs []string, options *store.Config) (store.Store, error)

var (
// Backend initializers
initializers = make(map[store.Backend]Initialize)
initializers = make(map[store.Backend]Initialize)
initializersMutex sync.RWMutex

supportedBackend = func() string {
keys := make([]string, 0, len(initializers))
Expand All @@ -27,6 +29,9 @@ var (

// NewStore creates an instance of store
func NewStore(backend store.Backend, addrs []string, options *store.Config) (store.Store, error) {
initializersMutex.Lock()
defer initializersMutex.Unlock()

if init, exists := initializers[backend]; exists {
return init(addrs, options)
}
Expand All @@ -36,5 +41,8 @@ func NewStore(backend store.Backend, addrs []string, options *store.Config) (sto

// AddStore adds a new store backend to valkeyrie
func AddStore(store store.Backend, init Initialize) {
initializersMutex.Lock()
defer initializersMutex.Unlock()

initializers[store] = init
}

0 comments on commit bf27888

Please sign in to comment.