dependency/kv_keys.go
func (d *KVKeysQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error) {
	select {
	case <-d.stopCh:
		return nil, nil, ErrStopped
	default:
	}

	opts = opts.Merge(&QueryOptions{
		Datacenter: d.dc,
	})

	log.Printf("[TRACE] %s: GET %s", d, &url.URL{
		Path:     "/v1/kv/" + d.prefix,
		RawQuery: opts.String(),
	})

	list, qm, err := clients.Consul().KV().Keys(d.prefix, "", opts.ToConsulOpts())
	if err != nil {
		return nil, nil, errors.Wrap(err, d.String())
	}

	keys := make([]string, len(list))
	for i, v := range list {
		v = strings.TrimPrefix(v, d.prefix)
		v = strings.TrimLeft(v, "/")
		keys[i] = v
	}

	log.Printf("[TRACE] %s: returned %d results", d, len(list))

	rm := &ResponseMetadata{
		LastIndex:   qm.LastIndex,
		LastContact: qm.LastContact,
	}

	return keys, rm, nil
}
func (d *KVKeysQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error) {
	select {
	case <-d.stopCh:
		return nil, nil, ErrStopped
	default:
	}

	opts = opts.Merge(&QueryOptions{
		Datacenter: d.dc,
	})

	log.Printf("[TRACE] %s: GET %s", d, &url.URL{
		Path:     "/v1/kv/" + d.prefix,
		RawQuery: opts.String(),
	})

	list, qm, err := clients.Consul().KV().Keys(d.prefix, "", opts.ToConsulOpts())
	if err != nil {
		return nil, nil, errors.Wrap(err, d.String())
	}

	keys := make([]string, len(list))
	for i, v := range list {
		v = strings.TrimPrefix(v, d.prefix)
		v = strings.TrimLeft(v, "/")
		keys[i] = v
	}

	log.Printf("[TRACE] %s: returned %d results", d, len(list))

	rm := &ResponseMetadata{
		LastIndex:   qm.LastIndex,
		LastContact: qm.LastContact,
	}

	return keys, rm, nil
}
// Fetch queries the Consul API defined by the given client.