本文整理汇总了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
}
}
}
示例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))
}
示例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)
})
}
示例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))
}
示例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))
}
示例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"))
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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))
}
示例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)
}
示例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)
}
}
}
}