// New is used to create a storage client based on our configuration.
func New(backend string) (StoreClient, error) {
	if backend == "" {
		backend = "etcd"
	}
	switch backend {
	case "consul":
		log.Notice("Consul address set to " + config.ConsulAddr())
		return consul.NewConsulClient(config.ConsulAddr())
	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.
		log.Notice("etcd nodes set to " + strings.Join(config.EtcdNodes(), ", "))
		return etcdutil.NewEtcdClient(config.EtcdNodes(), config.ClientCert(), config.ClientKey(), config.ClientCaKeys())
	case "env":
		return env.NewEnvClient()
	}
	return nil, errors.New("Invalid backend")
}
示例#2
0
文件: client.go 项目: imzhulei/confd
// 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.Notice("Backend nodes set to " + strings.Join(backendNodes, ", "))
	switch config.Backend {
	case "consul":
		return consul.NewConsulClient(backendNodes)
	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 "redis":
		return redis.NewRedisClient(backendNodes)
	case "env":
		return env.NewEnvClient()
	}
	return nil, errors.New("Invalid backend")
}