List returns a list of keys under a given prefix.
(ctx context.Context, prefix string)
| 18 | |
| 19 | // List returns a list of keys under a given prefix. |
| 20 | func (c *prefixedKVClient) List(ctx context.Context, prefix string) ([]string, error) { |
| 21 | keys, err := c.client.List(ctx, c.prefix+prefix) |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | |
| 26 | // Remove the prefix from the returned key. The prefix attached to the |
| 27 | // prefixed client is supposed to be transparent and the values returned |
| 28 | // by List should be able to be immediately inserted into the Get |
| 29 | // function, which means that our injected prefix needs to be removed. |
| 30 | for i := range keys { |
| 31 | keys[i] = strings.TrimPrefix(keys[i], c.prefix) |
| 32 | } |
| 33 | |
| 34 | return keys, nil |
| 35 | } |
| 36 | |
| 37 | // CAS atomically modifies a value in a callback. If the value doesn't exist, |
| 38 | // you'll get 'nil' as an argument to your callback. |