Skip to content

用于获取consul中键/值以及实现consul Watch机制监听的工具库

Notifications You must be signed in to change notification settings

longpi1/consul-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

consul-tool

用于获取consul中键/值以及实现consul Watch机制监听的工具库,关于watch机制的实现以及样例可查看 基于consul实现watch机制

初始化配置

conf := NewConfig()

With Options

conf := NewConfig(
    WithPrefix(prefix),             // consul kv prefix
    WithAddress(address),           // consul address
)

Init

if err := conf.Init();err !=nil {
    return err
}

Put

if err := conf.Put(key, value);err !=nil {
    return err
}

Delete

if err := conf.Delete(key);err !=nil {
    return err
}

Get

// 获取key
key := conf.KV.Key()

Get

// 获取value
key := conf.KV.Value()

Watch

conf.Watch(path, func(r *KV){
    r.Scan(x)
})

Stop Watch

// stop single watcher
conf.StopWatch(path)

// stop multiple watcher
conf.StopWatch(path1, path2)

// stop all watcher
conf.StopWatch()

About

用于获取consul中键/值以及实现consul Watch机制监听的工具库

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages