• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang discovery.CreateEntries函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/docker/swarm/discovery.CreateEntries函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateEntries函数的具体用法?Golang CreateEntries怎么用?Golang CreateEntries使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了CreateEntries函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: watchOnce

// Watch the store until either there's a store error or we receive a stop request.
// Returns false if we shouldn't attempt watching the store anymore (stop request received).
func (s *Discovery) watchOnce(stopCh <-chan struct{}, watchCh <-chan []*store.KVPair, discoveryCh chan discovery.Entries, errCh chan error) bool {
	for {
		select {
		case pairs := <-watchCh:
			if pairs == nil {
				return true
			}

			log.WithField("discovery", s.backend).Debugf("Watch triggered with %d nodes", len(pairs))

			// Convert `KVPair` into `discovery.Entry`.
			addrs := make([]string, len(pairs))
			for _, pair := range pairs {
				addrs = append(addrs, string(pair.Value))
			}

			entries, err := discovery.CreateEntries(addrs)
			if err != nil {
				errCh <- err
			} else {
				discoveryCh <- entries
			}
		case <-stopCh:
			// We were requested to stop watching.
			return false
		}
	}
}
开发者ID:jiangshengwu,项目名称:swarm,代码行数:30,代码来源:kv.go


示例2: fetch

func (s *Discovery) fetch() (discovery.Entries, error) {
	fileContent, err := ioutil.ReadFile(s.path)
	if err != nil {
		return nil, fmt.Errorf("failed to read '%s': %v", s.path, err)
	}
	return discovery.CreateEntries(parseFileContent(fileContent))
}
开发者ID:rkazak,项目名称:swarm,代码行数:7,代码来源:file.go


示例3: Watch

// Watch is exported
func (s *Discovery) Watch(callback discovery.WatchCallback) {
	s.store.WatchRange(s.prefix, "", s.heartbeat, func(kvalues []store.KVEntry) {
		// Traduce byte array entries to discovery.Entry
		entries, _ := discovery.CreateEntries(convertToStringArray(kvalues))
		callback(entries)
	})
}
开发者ID:AlphaStaxLLC,项目名称:libnetwork,代码行数:8,代码来源:kv.go


示例4: Fetch

// Fetch is exported
func (s *Discovery) Fetch() ([]*discovery.Entry, error) {
	fileContent, err := ioutil.ReadFile(s.path)
	if err != nil {
		return nil, err
	}
	return discovery.CreateEntries(parseFileContent(fileContent))
}
开发者ID:postfix,项目名称:golib-1,代码行数:8,代码来源:file.go


示例5: Fetch

// Fetch is exported
func (s *Discovery) Fetch() ([]*discovery.Entry, error) {
	addrs, err := s.store.GetRange(s.prefix)
	if err != nil {
		return nil, err
	}
	return discovery.CreateEntries(convertToStringArray(addrs))
}
开发者ID:AlphaStaxLLC,项目名称:libnetwork,代码行数:8,代码来源:kv.go


示例6: Fetch

func (s *FileDiscoveryService) Fetch() ([]*discovery.Entry, error) {
	data, err := ioutil.ReadFile(s.path)
	if err != nil {
		return nil, err
	}

	return discovery.CreateEntries(strings.Split(string(data), "\n"))
}
开发者ID:josephwinston,项目名称:libswarm,代码行数:8,代码来源:file.go


示例7: Fetch

// Fetch is exported
func (s *Discovery) Fetch() ([]*discovery.Entry, error) {
	addrs, _, err := s.conn.Children(s.fullpath())

	if err != nil {
		return nil, err
	}

	return discovery.CreateEntries(addrs)
}
开发者ID:postfix,项目名称:golib-1,代码行数:10,代码来源:zookeeper.go


示例8: Fetch

func (s *EtcdDiscoveryService) Fetch() ([]*discovery.Entry, error) {
	resp, err := s.client.Get(s.path, true, true)
	if err != nil {
		return nil, err
	}

	addrs := []string{}
	for _, n := range resp.Node.Nodes {
		addrs = append(addrs, n.Value)
	}
	return discovery.CreateEntries(addrs)
}
开发者ID:marsmensch,项目名称:swarm,代码行数:12,代码来源:etcd.go


示例9: Fetch

// Fetch is exported
func (s *Discovery) Fetch() ([]*discovery.Entry, error) {
	kv := s.client.KV()
	pairs, _, err := kv.List(s.prefix, nil)
	if err != nil {
		return nil, err
	}

	addrs := []string{}
	for _, pair := range pairs {
		if pair.Key == s.prefix {
			continue
		}
		addrs = append(addrs, string(pair.Value))
	}

	return discovery.CreateEntries(addrs)
}
开发者ID:postfix,项目名称:golib-1,代码行数:18,代码来源:consul.go


示例10: fetch

// Fetch returns the list of entries for the discovery service at the specified endpoint
func (s *Discovery) fetch() (discovery.Entries, error) {
	resp, err := http.Get(fmt.Sprintf("%s/%s/%s", s.url, "clusters", s.token))
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	var addrs []string
	if resp.StatusCode == http.StatusOK {
		if err := json.NewDecoder(resp.Body).Decode(&addrs); err != nil {
			return nil, fmt.Errorf("Failed to decode response: %v", err)
		}
	} else {
		return nil, fmt.Errorf("Failed to fetch entries, Discovery service returned %d HTTP status code", resp.StatusCode)
	}

	return discovery.CreateEntries(addrs)
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:20,代码来源:token.go


示例11: TestRegister

func TestRegister(t *testing.T) {
	d := &Discovery{token: "TEST_TOKEN", url: discoveryURL, heartbeat: 1}
	expected := "127.0.0.1:2675"
	expectedEntries, err := discovery.CreateEntries([]string{expected})
	assert.NoError(t, err)

	// Register
	assert.NoError(t, d.Register(expected))

	// Watch
	ch, errCh := d.Watch(nil)
	select {
	case entries := <-ch:
		assert.True(t, entries.Equals(expectedEntries))
	case err := <-errCh:
		t.Fatal(err)
	case <-time.After(5 * time.Second):
		t.Fatal("Timed out")
	}

	assert.NoError(t, d.Register(expected))
}
开发者ID:rkazak,项目名称:swarm,代码行数:22,代码来源:token_test.go


示例12: fetch

// Fetch returns the list of entries for the discovery service at the specified endpoint
func (s *Discovery) fetch() (discovery.Entries, error) {
	// Here, we contact the serf agent and ask for a list of members
	// We have to send back entries, which are basically a host and a port (see discovery.go)
	output, err := exec.Command("./agent_members.sh").Output()

	if err != nil {
		return nil, err
	}

	all_lines := strings.Split(string(output[:]), "\n")
	lines := all_lines[:len(all_lines)-1]
	var addrs []string
	for _, line := range lines {
		fields := strings.Fields(line)
		fmt.Println("FIELDS %d", len(fields))
		if len(fields) != 3 {
			return nil, errors.New("Error while parsing the output of serf members : Wrong number of fields")
		}
		addrs = append(addrs, fields[1])
	}

	return discovery.CreateEntries(addrs)
}
开发者ID:adouang,项目名称:swarm,代码行数:24,代码来源:serf.go


示例13: Watch

// Watch is exported
func (s *Discovery) Watch(callback discovery.WatchCallback) {

	addrs, _, eventChan, err := s.conn.ChildrenW(s.fullpath())
	if err != nil {
		log.WithField("name", "zk").Debug("Discovery watch aborted")
		return
	}
	entries, err := discovery.CreateEntries(addrs)
	if err == nil {
		callback(entries)
	}

	for e := range eventChan {
		if e.Type == zk.EventNodeChildrenChanged {
			log.WithField("name", "zk").Debug("Discovery watch triggered")
			entries, err := s.Fetch()
			if err == nil {
				callback(entries)
			}
		}

	}

}
开发者ID:postfix,项目名称:golib-1,代码行数:25,代码来源:zookeeper.go



注:本文中的github.com/docker/swarm/discovery.CreateEntries函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang discovery.New函数代码示例发布时间:2022-05-23
下一篇:
Golang queue.NewQueue函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap