本文整理匯總了Golang中github.com/eBay/fabio/_third_party/github.com/hashicorp/consul/api.Client.KV方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.KV方法的具體用法?Golang Client.KV怎麽用?Golang Client.KV使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eBay/fabio/_third_party/github.com/hashicorp/consul/api.Client
的用法示例。
在下文中一共展示了Client.KV方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: putKV
func putKV(client *api.Client, key, value string, index uint64) (bool, error) {
p := &api.KVPair{Key: key[1:], Value: []byte(value), ModifyIndex: index}
ok, _, err := client.KV().CAS(p, nil)
if err != nil {
return false, err
}
return ok, nil
}
示例2: getKV
func getKV(client *api.Client, key string, waitIndex uint64) (string, uint64, error) {
q := &api.QueryOptions{RequireConsistent: true, WaitIndex: waitIndex}
kvpair, meta, err := client.KV().Get(key, q)
if err != nil {
return "", 0, err
}
if kvpair == nil {
return "", meta.LastIndex, nil
}
return strings.TrimSpace(string(kvpair.Value)), meta.LastIndex, nil
}
示例3: nextValue
func nextValue(client *api.Client, path string, lastIndex uint64) (string, uint64) {
for {
q := &api.QueryOptions{RequireConsistent: true, WaitIndex: lastIndex}
kvpair, meta, err := client.KV().Get(path, q)
if err != nil {
log.Printf("[WARN] Error fetching config from %s. %v", path, err)
time.Sleep(time.Second)
continue
}
if kvpair == nil {
return "", meta.LastIndex
}
return strings.TrimSpace(string(kvpair.Value)), meta.LastIndex
}
}