traefik/vendor/github.com/abronan/valkeyrie/valkeyrie.go
2018-01-24 17:52:03 +01:00

40 lines
995 B
Go

package valkeyrie
import (
"fmt"
"sort"
"strings"
"github.com/abronan/valkeyrie/store"
)
// Initialize creates a new Store object, initializing the client
type Initialize func(addrs []string, options *store.Config) (store.Store, error)
var (
// Backend initializers
initializers = make(map[store.Backend]Initialize)
supportedBackend = func() string {
keys := make([]string, 0, len(initializers))
for k := range initializers {
keys = append(keys, string(k))
}
sort.Strings(keys)
return strings.Join(keys, ", ")
}()
)
// NewStore creates an instance of store
func NewStore(backend store.Backend, addrs []string, options *store.Config) (store.Store, error) {
if init, exists := initializers[backend]; exists {
return init(addrs, options)
}
return nil, fmt.Errorf("%s %s", store.ErrBackendNotSupported.Error(), supportedBackend)
}
// AddStore adds a new store backend to valkeyrie
func AddStore(store store.Backend, init Initialize) {
initializers[store] = init
}