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


Golang store.CreateEndpoints函數代碼示例

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


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

示例1: New

// New creates a new Etcd client given a list
// of endpoints and an optional tls config
func New(addrs []string, options *store.Config) (store.Store, error) {
	s := &Etcd{}

	entries := store.CreateEndpoints(addrs, "http")
	s.client = etcd.NewClient(entries)

	// Set options
	if options != nil {
		if options.TLS != nil {
			s.setTLS(options.TLS)
		}
		if options.ConnectionTimeout != 0 {
			s.setTimeout(options.ConnectionTimeout)
		}
	}

	// Periodic SyncCluster
	go func() {
		for {
			s.client.SyncCluster()
			time.Sleep(periodicSync)
		}
	}()

	return s, nil
}
開發者ID:sanimej,項目名稱:libkv,代碼行數:28,代碼來源:etcd.go

示例2: New

// New creates a new Etcd client given a list
// of endpoints and an optional tls config
func New(addrs []string, options *store.Config) (store.Store, error) {
	s := &Etcd{}

	var (
		entries []string
		err     error
	)

	// Create the etcd client
	if options != nil && options.ClientTLS != nil {
		entries = store.CreateEndpoints(addrs, "https")
		s.client, err = etcd.NewTLSClient(entries, options.ClientTLS.CertFile, options.ClientTLS.KeyFile, options.ClientTLS.CACertFile)
		if err != nil {
			return nil, err
		}
	} else {
		entries = store.CreateEndpoints(addrs, "http")
		s.client = etcd.NewClient(entries)
	}

	// Set options
	if options != nil {
		// Plain TLS config overrides ClientTLS if specified
		if options.TLS != nil {
			s.setTLS(options.TLS, addrs)
		}
		if options.ConnectionTimeout != 0 {
			s.setTimeout(options.ConnectionTimeout)
		}
	}

	// Periodic SyncCluster
	go func() {
		for {
			s.client.SyncCluster()
			time.Sleep(periodicSync)
		}
	}()

	return s, nil
}
開發者ID:nixuw,項目名稱:docker,代碼行數:43,代碼來源:etcd.go

示例3: setTLS

// SetTLS sets the tls configuration given a tls.Config scheme
func (s *Etcd) setTLS(tls *tls.Config, addrs []string) {
	entries := store.CreateEndpoints(addrs, "https")
	s.client.SetCluster(entries)

	// Set transport
	t := http.Transport{
		Dial: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,
		TLSHandshakeTimeout: 10 * time.Second,
		TLSClientConfig:     tls,
	}
	s.client.SetTransport(&t)
}
開發者ID:nixuw,項目名稱:docker,代碼行數:16,代碼來源:etcd.go

示例4: setTLS

// SetTLS sets the tls configuration given a tls.Config scheme
func setTLS(cfg *etcd.Config, tls *tls.Config, addrs []string) {
	entries := store.CreateEndpoints(addrs, "https")
	cfg.Endpoints = entries

	// Set transport
	t := http.Transport{
		Dial: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,
		TLSHandshakeTimeout: 10 * time.Second,
		TLSClientConfig:     tls,
	}

	cfg.Transport = &t
}
開發者ID:MiLk,項目名稱:swarm,代碼行數:17,代碼來源:etcd.go

示例5: New

// New creates a new Etcd client given a list
// of endpoints and an optional tls config
func New(addrs []string, options *store.Config) (store.Store, error) {
	s := &Etcd{}

	var (
		entries []string
		err     error
	)

	entries = store.CreateEndpoints(addrs, "http")
	cfg := &etcd.Config{
		Endpoints:               entries,
		Transport:               etcd.DefaultTransport,
		HeaderTimeoutPerRequest: 3 * time.Second,
	}

	// Set options
	if options != nil {
		if options.TLS != nil {
			setTLS(cfg, options.TLS, addrs)
		}
		if options.ConnectionTimeout != 0 {
			setTimeout(cfg, options.ConnectionTimeout)
		}
		if options.Username != "" {
			setCredentials(cfg, options.Username, options.Password)
		}
	}

	c, err := etcd.New(*cfg)
	if err != nil {
		log.Fatal(err)
	}

	s.client = etcd.NewKeysAPI(c)

	// Periodic Cluster Sync
	go func() {
		for {
			if err := c.AutoSync(context.Background(), periodicSync); err != nil {
				return
			}
		}
	}()

	return s, nil
}
開發者ID:CadeLaRen,項目名稱:docker-3,代碼行數:48,代碼來源:etcd.go


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