Пример #1
0
// ListPrefix is used to list a subtree of an entity, such as listing volume by policy.
func (c *Client) ListPrefix(prefix string, obj db.Entity) ([]db.Entity, error) {
	resp, err := c.client.Get(context.Background(), c.qualified(path.Join(obj.Prefix(), prefix)), &client.GetOptions{Recursive: true})
	if err != nil {
		return nil, err
	}

	return c.traverse(resp.Node, obj), nil
}
Пример #2
0
// ListPrefix lists all the entities under prefix instead of listing the whole keyspace.
func (c *Client) ListPrefix(prefix string, obj db.Entity) ([]db.Entity, error) {
	pairs, _, err := c.client.KV().List(c.qualified(path.Join(obj.Prefix(), prefix)), nil)
	if err != nil {
		return nil, err
	}

	entities := []db.Entity{}

	for _, pair := range pairs {
		copy, err := helpers.ReadAndSet(c, obj, pair.Key, pair.Value)
		if err != nil {
			return nil, err
		}

		entities = append(entities, copy)
	}

	return entities, nil
}
Пример #3
0
// WatchPrefixStop stops a watch.
func (c *Client) WatchPrefixStop(obj db.Entity) error {
	return helpers.WatchStop(c, obj.Prefix(), c.watchers, &c.watcherMutex)
}
Пример #4
0
// WatchPrefix watches a directory prefix for changes.
func (c *Client) WatchPrefix(obj db.Entity) (chan db.Entity, chan error) {
	// these paths are qualified in watchInternal
	return helpers.WrapWatch(c, obj, obj.Prefix(), true, c.watchers, &c.watcherMutex, c.watchInternal)
}
Пример #5
0
// WatchPrefix watches all items under the given entity's prefix
func (c *Client) WatchPrefix(obj db.Entity) (chan db.Entity, chan error) {
	return helpers.WrapWatch(c, obj, obj.Prefix(), true, c.watchers, &c.watcherMutex, c.startWatch)
}
Пример #6
0
// WatchPrefixStop stops
func (c *Client) WatchPrefixStop(obj db.Entity) error {
	return c.watchStopPath(obj.Prefix())
}
Пример #7
0
// WatchPrefix watches all items under the given entity's prefix
func (c *Client) WatchPrefix(obj db.Entity) (chan db.Entity, chan error) {
	return c.watchPath(obj, obj.Prefix(), true)
}