示例#1
0
// createStoreClient is used to create a storage client based
// on our configuration. Either an etcd or Consul client.
func createStoreClient() (template.StoreClient, error) {
	if config.Consul() {
		log.Notice("Consul address set to " + config.ConsulAddr())
		return consul.NewConsulClient(config.ConsulAddr())
	} else {
		// 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())
	}
}
示例#2
0
文件: confd.go 项目: raizyr/confd
// createStoreClient is used to create a storage client based
// on our configuration. Either an etcd or Consul client.
func createStoreClient(backend string) (template.StoreClient, error) {
	log.Notice("Backend set to " + backend)
	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")
}