// 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 }
// 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 }
// WatchPrefixStop stops a watch. func (c *Client) WatchPrefixStop(obj db.Entity) error { return helpers.WatchStop(c, obj.Prefix(), c.watchers, &c.watcherMutex) }
// 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) }
// 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) }
// WatchPrefixStop stops func (c *Client) WatchPrefixStop(obj db.Entity) error { return c.watchStopPath(obj.Prefix()) }
// 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) }