用于获取consul中键/值以及实现consul Watch机制监听的工具库,关于watch机制的实现以及样例可查看 基于consul实现watch机制
conf := NewConfig()
conf := NewConfig(
WithPrefix(prefix), // consul kv prefix
WithAddress(address), // consul address
)
if err := conf.Init();err !=nil {
return err
}
if err := conf.Put(key, value);err !=nil {
return err
}
if err := conf.Delete(key);err !=nil {
return err
}
// 获取key
key := conf.KV.Key()
// 获取value
key := conf.KV.Value()
conf.Watch(path, func(r *KV){
r.Scan(x)
})
// stop single watcher
conf.StopWatch(path)
// stop multiple watcher
conf.StopWatch(path1, path2)
// stop all watcher
conf.StopWatch()