forked from kelseyhightower/confd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
57 lines (53 loc) · 2.02 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package backends
import (
"errors"
"strings"
"github.com/kelseyhightower/confd/backends/consul"
"github.com/kelseyhightower/confd/backends/dynamodb"
"github.com/kelseyhightower/confd/backends/env"
"github.com/kelseyhightower/confd/backends/etcd"
"github.com/kelseyhightower/confd/backends/rancher"
"github.com/kelseyhightower/confd/backends/redis"
"github.com/kelseyhightower/confd/backends/stackengine"
"github.com/kelseyhightower/confd/backends/zookeeper"
"github.com/kelseyhightower/confd/log"
)
// The StoreClient interface is implemented by objects that can retrieve
// key/value pairs from a backend store.
type StoreClient interface {
GetValues(keys []string) (map[string]string, error)
WatchPrefix(prefix string, waitIndex uint64, stopChan chan bool) (uint64, error)
}
// New is used to create a storage client based on our configuration.
func New(config Config) (StoreClient, error) {
if config.Backend == "" {
config.Backend = "etcd"
}
backendNodes := config.BackendNodes
log.Info("Backend nodes set to " + strings.Join(backendNodes, ", "))
switch config.Backend {
case "consul":
return consul.New(config.BackendNodes, config.Scheme,
config.ClientCert, config.ClientKey,
config.ClientCaKeys)
case "etcd":
// Create the etcd client upfront and use it for the life of the process.
// The etcdClient is an http.Client and designed to be reused.
return etcd.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys)
case "zookeeper":
return zookeeper.NewZookeeperClient(backendNodes)
case "rancher":
return rancher.NewRancherClient(backendNodes)
case "redis":
return redis.NewRedisClient(backendNodes)
case "env":
return env.NewEnvClient()
case "dynamodb":
table := config.Table
log.Info("DynamoDB table set to " + table)
return dynamodb.NewDynamoDBClient(table)
case "stackengine":
return stackengine.NewStackEngineClient(backendNodes, config.Scheme, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.AuthToken)
}
return nil, errors.New("Invalid backend")
}