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


Golang Client.SetCluster方法代碼示例

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


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

示例1: NewEtcdClient

func NewEtcdClient(addr string, dialTimeout time.Duration) (*EtcdClient, error) {
	var c *api.Client
	/*
		var err error
		if cert != "" && key != "" {
			c, err = etcd.NewTLSClient(machines, cert, key, caCert)
			if err != nil {
				return &Client{c}, err
			}
		} else {
			c = etcd.NewClient(machines)
		}
	*/

	// machine addresses
	machines := []string{addr}

	// create custom client
	c = api.NewClient(machines)
	if !c.SetCluster(machines) {
		return nil, errors.New("cannot connect to etcd cluster: " + addr)
	}

	// configure dial timeout
	c.SetDialTimeout(dialTimeout)

	return &EtcdClient{addr: addr, client: c}, nil
}
開發者ID:haoyixin,項目名稱:parkeeper,代碼行數:28,代碼來源:etcdclient.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: 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

示例4: detectRunningEtcd

func (etcd *ETCDClusterRunner) detectRunningEtcd(index int) bool {
	var client *etcdclient.Client

	if etcd.serverSSL == nil {
		client = etcdclient.NewClient([]string{})
	} else {
		var err error
		client, err = etcdstoreadapter.NewETCDTLSClient(
			[]string{etcd.clientURL(index)},
			etcd.serverSSL.CertFile,
			etcd.serverSSL.KeyFile,
			etcd.serverSSL.CAFile,
		)
		Expect(err).NotTo(HaveOccurred())
	}
	return client.SetCluster([]string{etcd.clientURL(index)})
}
開發者ID:idouba,項目名稱:gorouter,代碼行數:17,代碼來源:etcd_cluster_runner.go

示例5: 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

示例6: 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)
	}
	// Configure the DialTimeout, since 1 second is often too short
	c.SetDialTimeout(time.Duration(3) * time.Second)
	success := c.SetCluster(machines)
	if !success {
		return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
	}
	return &Client{c}, nil
}
開發者ID:radartools,項目名稱:confd,代碼行數:20,代碼來源:client.go

示例7: 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) {
func NewEtcdClient(machines []string, cert, key string, caCert string, basicAuth bool, username string, password 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)
	}
	if basicAuth {
		c.SetCredentials(username, password)
	}
	// Configure the DialTimeout, since 1 second is often too short
	c.SetDialTimeout(time.Duration(3) * time.Second)
	success := c.SetCluster(machines)
	if !success {
		return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
	}
	return &Client{c}, nil
}
開發者ID:tanbokan,項目名稱:confd,代碼行數:25,代碼來源:client.go

示例8: 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, noDiscover bool) (*Client, error) {
	var c *goetcd.Client
	var err error
	machines = prependSchemeToMachines(machines)
	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)

	// If noDiscover is not set, we should locate the whole etcd cluster.
	if !noDiscover {
		success := c.SetCluster(machines)
		if !success {
			return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
		}
	}
	return &Client{c}, nil
}
開發者ID:projectcalico,項目名稱:confd,代碼行數:26,代碼來源:client.go


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