Esempio n. 1
0
func (g *Backend) Records(name string, exact bool) ([]msg.Service, error) {
	etcd.GetLogger().Printf("backend call Records(%q)", name)
	path, star := msg.PathWithWildcard(name)
	r, err := g.get(path, true)
	if err != nil {
		return nil, err
	}
	segments := strings.Split(msg.Path(name), "/")
	switch {
	case exact && r.Node.Dir:
		return nil, nil
	case r.Node.Dir:
		return g.loopNodes(&r.Node.Nodes, segments, star, nil)
	default:
		return g.loopNodes(&etcd.Nodes{r.Node}, segments, false, nil)
	}
}
Esempio n. 2
0
func (g *Backend) ReverseRecord(name string) (*msg.Service, error) {
	etcd.GetLogger().Printf("backend call ReverseRecord(%q)", name)
	path, star := msg.PathWithWildcard(name)
	if star {
		return nil, fmt.Errorf("reverse can not contain wildcards")
	}
	r, err := g.get(path, true)
	if err != nil {
		return nil, err
	}
	if r.Node.Dir {
		return nil, fmt.Errorf("reverse must not be a directory")
	}
	segments := strings.Split(msg.Path(name), "/")
	records, err := g.loopNodes(&etcd.Nodes{r.Node}, segments, false, nil)
	if err != nil {
		return nil, err
	}
	if len(records) != 1 {
		return nil, fmt.Errorf("must be only one service record")
	}
	return &records[0], nil
}