當前位置: 首頁>>代碼示例>>Golang>>正文


Golang etcd.NewTLSClient函數代碼示例

本文整理匯總了Golang中github.com/coreos/go-etcd/etcd.NewTLSClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTLSClient函數的具體用法?Golang NewTLSClient怎麽用?Golang NewTLSClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewTLSClient函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewEtcd

func NewEtcd(prefixKey string, config *EtcdConfig) (*Etcd, error) {
	var (
		client *etcd.Client
		err    error
	)

	if config.CertFile != "" && config.KeyFile != "" {
		if client, err = etcd.NewTLSClient(config.Machines, config.CertFile, config.KeyFile, config.CaFile); err != nil {
			Logger.Error("Failed to connect to Etcd. Error: %+v.", err)
			return nil, err
		}
	} else {
		client = etcd.NewClient(config.Machines)
	}

	// Set the default value if not provided.
	if config.EtcdConsistency == "" {
		config.EtcdConsistency = etcd.STRONG_CONSISTENCY
	}

	if err = client.SetConsistency(config.EtcdConsistency); err != nil {
		Logger.Error("Failed to set Etcd consitency. Error: %+v.", err)
		return nil, err
	}

	return &Etcd{client: client, prefixKey: prefixKey}, nil
}
開發者ID:yonglehou,項目名稱:maestro,代碼行數:27,代碼來源:etcd.go

示例2: NewEtcdClient

// NewEtcdClient returns an *etcd.Client with a connection to named machines.
// It returns an error if a connection to the cluster cannot be made.
func NewEtcdClient(machines []string, cert, key string, caCert string) (*Client, error) {
	var c *goetcd.Client
	var err error
	if cert != "" && key != "" {
		c, err = goetcd.NewTLSClient(machines, cert, key, caCert)
		if err != nil {
			return &Client{c}, err
		}
	} else {
		c = goetcd.NewClient(machines)
	}
	// Configure the DialTimeout, since 1 second is often too short
	c.SetDialTimeout(time.Duration(3) * time.Second)

	maxConnectAttempts := 10
	for attempt := 1; attempt <= maxConnectAttempts; attempt++ {
		success := c.SetCluster(machines)
		if success {
			break
			return &Client{c}, nil
		}

		if attempt == maxConnectAttempts {
			break
			return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
		}
		log.Info(fmt.Sprintf("[Attempt: %d] Attempting access to etcd after 5 second sleep", attempt))
		time.Sleep(5 * time.Second)
	}

	return &Client{c}, nil
}
開發者ID:Lineberty,項目名稱:confd,代碼行數:34,代碼來源:client.go

示例3: New

func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
	urls := make([]string, 0)
	if uri.Host != "" {
		urls = append(urls, f.Scheme+"://"+uri.Host)
	} else {
		urls = append(urls, f.Scheme+"://127.0.0.1:4001")
	}

	if f.Scheme == "https" {
		cert := os.Getenv("ETCD_CERTFILE")
		key := os.Getenv("ETCD_KEYFILE")
		caCert := os.Getenv("ETCD_CAFILE")
		client, err := etcd2.NewTLSClient(urls, cert, key, caCert)
		if err != nil {
			log.Fatal("etcd: error creating tls client", err)
		}
		return &EtcdAdapter{client2: client, path: uri.Path}
	}

	res, err := http.Get(urls[0] + "/version")
	if err != nil {
		log.Fatal("etcd: error retrieving version", err)
	}

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	if match, _ := regexp.Match("0\\.4\\.*", body); match == true {
		log.Println("etcd: using v0 client")
		return &EtcdAdapter{client: etcd.NewClient(urls), path: uri.Path}
	}

	return &EtcdAdapter{client2: etcd2.NewClient(urls), path: uri.Path}
}
開發者ID:genki,項目名稱:registrator,代碼行數:34,代碼來源:etcd.go

示例4: newEtcdClient

func newEtcdClient(c *EtcdConfig) (*etcd.Client, error) {
	if c.Keyfile != "" || c.Certfile != "" || c.CAFile != "" {
		return etcd.NewTLSClient(c.Endpoints, c.Certfile, c.Keyfile, c.CAFile)
	} else {
		return etcd.NewClient(c.Endpoints), nil
	}
}
開發者ID:rajkotecha,項目名稱:origin,代碼行數:7,代碼來源:registry.go

示例5: Client

func Client() *etcd.Client {
	clientSingletonO.Do(func() {
		host := "http://localhost:4001"
		if len(os.Getenv("ETCD_HOST")) != 0 {
			host = os.Getenv("ETCD_HOST")
		}

		cacert := os.Getenv("ETCD_CACERT")
		tlskey := os.Getenv("ETCD_TLS_KEY")
		tlscert := os.Getenv("ETCD_TLS_CERT")
		if len(cacert) != 0 && len(tlskey) != 0 && len(tlscert) != 0 {
			if !strings.Contains(host, "https://") {
				host = strings.Replace(host, "http", "https", 1)
			}
			c, err := etcd.NewTLSClient([]string{host}, tlscert, tlskey, cacert)
			if err != nil {
				panic(err)
			}
			clientSingleton = c
		} else {
			clientSingleton = etcd.NewClient([]string{host})
		}
	})
	return clientSingleton
}
開發者ID:xwangkai,項目名稱:etcd-discovery,代碼行數:25,代碼來源:init.go

示例6: New

func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
	urls := make([]string, 0)
	if uri.Host != "" {
		urls = append(urls, f.Scheme+"://"+uri.Host)
	} else {
		urls = append(urls, f.Scheme+"://127.0.0.1:4001")
	}

	if len(uri.Path) < 2 {
		log.Fatal("skydns2: dns domain required e.g.: skydns2://<host>/<domain>")
	}

	if f.Scheme == "https" {
		cert := os.Getenv("ETCD_CERTFILE")
		key := os.Getenv("ETCD_KEYFILE")
		caCert := os.Getenv("ETCD_CAFILE")
		client, err := etcd.NewTLSClient(urls, cert, key, caCert)
		if err != nil {
			log.Fatal("etcd: error creating tls client", err)
		}
		return &Skydns2Adapter{client: client, path: domainPath(uri.Path[1:])}
	}

	return &Skydns2Adapter{client: etcd.NewClient(urls), path: domainPath(uri.Path[1:])}
}
開發者ID:genki,項目名稱:registrator,代碼行數:25,代碼來源:skydns2.go

示例7: newEtcdLockClient

func newEtcdLockClient(e *EtcdLock) (utils.Registry, error) {
	var c utils.Registry
	// if all are set, try to use tls
	if *e.CertFile != "" && *e.KeyFile != "" && *e.CAFile != "" {
		return etcd.NewTLSClient(*e.Members, *e.CertFile, *e.KeyFile, *e.CAFile)
	}
	c = etcd.NewClient(*e.Members)

	return c, nil
}
開發者ID:roboll,項目名稱:elector,代碼行數:10,代碼來源:etcd.go

示例8: NewClient

func NewClient(machines []string, cert, key, ca string) (client *Client, err error) {
	client = &Client{}
	if cert != "" && key != "" && ca != "" {
		if client.Client, err = etcd.NewTLSClient(machines, cert, key, ca); err != nil {
			return
		}
	} else {
		client.Client = etcd.NewClient(machines)
	}
	return
}
開發者ID:alemic,項目名稱:gleam,代碼行數:11,代碼來源:client.go

示例9: NewEtcdClient

func NewEtcdClient() (client *etcd.Client) {
	if etcdClient != nil {
		return etcdClient
	}

	tlsEnabled := os.Getenv("ETCDCTL_TLS")
	tls := len(tlsEnabled) > 0

	certFile := os.Getenv("ETCDCTL_CERT_FILE")
	keyFile := os.Getenv("ETCDCTL_KEY_FILE")
	caFile := os.Getenv("ETCDCTL_TRUSTED_CA_FILE")

	var err error
	peersStr := os.Getenv("ETCDCTL_PEERS")
	if len(peersStr) > 0 {
		log.Println("Connecting to etcd peers : " + peersStr)
		peers := strings.Split(peersStr, ",")
		if tls {
			etcdClient, err = etcd.NewTLSClient(peers, certFile, keyFile, caFile)
			if err != nil {
				log.Fatal(err)
			}
		} else {
			etcdClient = etcd.NewClient(peers)
		}
	} else {
		if tls {
			etcdClient, err = etcd.NewTLSClient(nil, certFile, keyFile, caFile)
			if err != nil {
				log.Fatal(err)
			}
		} else {
			etcdClient = etcd.NewClient(nil)
		}
	}

	return etcdClient
}
開發者ID:keithballdotnet,項目名稱:couchbase-array,代碼行數:38,代碼來源:couchbase.go

示例10: NewClient

//新建注冊中心客戶端
func (c *Conn) NewClient() (result *registry, err error) {
	var client *etcd.Client
	if c.Tls == true {
		//https conn
		client, err = etcd.NewTLSClient(c.Hosts, c.Cert, c.Key, c.CaCert)
	} else {
		//http conn
		client = etcd.NewClient(c.Hosts)
		if client == nil {
			err = fmt.Errorf("client init faild")
		}
	}
	return &registry{pool: client}, err
}
開發者ID:chuangyou,項目名稱:qsf,代碼行數:15,代碼來源:registry.go

示例11: newClient

func newClient() (client *etcd.Client) {
	if len(machines) == 1 && machines[0] == "" {
		machines[0] = "http://127.0.0.1:4001"
	}
	if strings.HasPrefix(machines[0], "https://") {
		var err error
		if client, err = etcd.NewTLSClient(machines, tlspem, tlskey, ""); err != nil {
			log.Fatal(err)
		}
	} else {
		client = etcd.NewClient(machines)
	}
	client.SyncCluster()
	return client
}
開發者ID:njhartwell,項目名稱:skydns2,代碼行數:15,代碼來源:main.go

示例12: newClient

func newClient(machines []string, tlsCert, tlsKey, tlsCACert string) (client *etcd.Client) {
	// set default if not specified in env
	if len(machines) == 1 && machines[0] == "" {
		machines[0] = "http://127.0.0.1:4001"
	}
	if strings.HasPrefix(machines[0], "https://") {
		var err error
		// TODO(miek): machines is local, the rest is global, ugly.
		if client, err = etcd.NewTLSClient(machines, tlsCert, tlsKey, tlsCACert); err != nil {
			// TODO(miek): would be nice if this wasn't a fatal error
			log.Fatalf("skydns: failure to connect: %s", err)
		}
		return client
	}
	return etcd.NewClient(machines)
}
開發者ID:schatt,項目名稱:skydns,代碼行數:16,代碼來源:main.go

示例13: NewEtcdClient

// NewEtcdClient returns an *etcd.Client with a connection to named machines.
// It returns an error if a connection to the cluster cannot be made.
func NewEtcdClient(machines []string, cert, key string, caCert string) (*Client, error) {
	var c *etcd.Client
	if cert != "" && key != "" {
		c, err := etcd.NewTLSClient(machines, cert, key, caCert)
		if err != nil {
			return &Client{c}, err
		}
	} else {
		c = etcd.NewClient(machines)
	}
	success := c.SetCluster(machines)
	if !success {
		return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
	}
	return &Client{c}, nil
}
開發者ID:carriercomm,項目名稱:haproxy-confd,代碼行數:18,代碼來源:client.go

示例14: reconnect

func (n *ng) reconnect() error {
	n.Close()
	var client *etcd.Client
	if n.options.EtcdCertFile == "" && n.options.EtcdKeyFile == "" {
		client = etcd.NewClient(n.nodes)
	} else {
		var err error
		if client, err = etcd.NewTLSClient(n.nodes, n.options.EtcdCertFile, n.options.EtcdKeyFile, n.options.EtcdCaFile); err != nil {
			return err
		}
	}
	if err := client.SetConsistency(n.options.EtcdConsistency); err != nil {
		return err
	}
	n.client = client
	return nil
}
開發者ID:vnadgir-ef,項目名稱:vulcand,代碼行數:17,代碼來源:etcd.go

示例15: NewClient

// NewClient returns an *etcd.Client with a connection to the named machines.
// It will return an error if a connection to the cluster cannot be made.
// The parameter machines needs to be a full URL with schemas.
// e.g. "http://localhost:4001" will work, but "localhost:4001" will not.
func NewClient(machines []string, cert, key, caCert string) (Client, error) {
	var c *etcd.Client
	var err error

	if cert != "" && key != "" {
		c, err = etcd.NewTLSClient(machines, cert, key, caCert)
		if err != nil {
			return nil, err
		}
	} else {
		c = etcd.NewClient(machines)
	}
	success := c.SetCluster(machines)
	if !success {
		return nil, fmt.Errorf("cannot connect to the etcd cluster: %s", strings.Join(machines, ","))
	}
	return &client{c}, nil
}
開發者ID:nimmen,項目名稱:kit,代碼行數:22,代碼來源:client.go


注:本文中的github.com/coreos/go-etcd/etcd.NewTLSClient函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。