libkv icon indicating copy to clipboard operation
libkv copied to clipboard

Add mapping layer for keys

Open wienczny opened this issue 10 years ago • 0 comments

I think it would be useful to have a simple mapping function for each store to allow access to arbitrary keys. This is especially useful for stores like consul where currently only a subset of keys is accessible (e.g. /kv). There are additional keys available below /catalog/services for example. I propose some changes to the API of libkv:

  • Add namespace constants to libkv. These are for example const (KV = 0, AGENT = 1, CATALOG = 2, SESSIONS=3, HEALTHCHECKS=4, ACLS=5, EVENTS=6, STATUS=7 ) These are Consul namespaces which, except for KV, are not accessible by libkv. There could be more.
  • Add an optional func map(namespace int, key string) (int, string) to each store's configuration object. This function allow mapping of namespaces and strings to different values as required by the store implementation.
  • Add a new ...NS() function to Store for each function accepting a key string or directory string. This function should have an additional first parameter namespace int which accepts the constants defined above. It applies the map-function to its parameters namespace and key and then calls the approriate store methods according to the mapped namespace and key.

If sane defaults are provided this should not require any change for any existing code outside of libkv. It should provide allow to support more stores and their features. Beside support for more namespaces in Consul the mapping function should allow schema changes and migrations from one store to another.

wienczny avatar Aug 19 '15 00:08 wienczny