本文整理匯總了Golang中github.com/hashicorp/consul/api.KV.Keys方法的典型用法代碼示例。如果您正苦於以下問題:Golang KV.Keys方法的具體用法?Golang KV.Keys怎麽用?Golang KV.Keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/consul/api.KV
的用法示例。
在下文中一共展示了KV.Keys方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewPackageCatalog
func NewPackageCatalog(kv *consul.KV, repositoryRoot string) (*packageCatalog, error) {
catalog := &packageCatalog{kv: kv}
pkgIndex := make(map[string]map[string]map[string]string)
keys, _, err := kv.Keys(repositoryRoot, "", nil)
if err != nil {
return nil, err
}
sort.Strings(keys)
// package key example: mantl-install/repository/0/repo/packages/S/spark/3/config.json
for _, key := range keys {
parts := strings.Split(key, "/")
if len(parts) == 9 {
repoIdx := parts[2]
name := parts[6]
verIdx := parts[7]
_, ok := pkgIndex[name]
if !ok {
pkgIndex[name] = make(map[string]map[string]string)
}
_, ok = pkgIndex[name][repoIdx]
if !ok {
pkgIndex[name][repoIdx] = make(map[string]string)
}
_, ok = pkgIndex[name][repoIdx][verIdx]
if !ok {
pkgKey := key[0 : strings.LastIndex(key, "/")+1]
pkgIndex[name][repoIdx][verIdx] = pkgKey
}
}
}
catalog.catalog = pkgIndex
return catalog, nil
}
示例2:
}
type ConsulProvider struct {
Watch bool
Endpoint string
Prefix string
Filename string
consulClient *api.Client
}
var kvClient *api.KV
var ConsulFuncMap = template.FuncMap{
"List": func(keys ...string) []string {
joinedKeys := strings.Join(keys, "")
keysPairs, _, err := kvClient.Keys(joinedKeys, "/", nil)
if err != nil {
log.Error("Error getting keys ", joinedKeys, err)
return nil
}
keysPairs = fun.Filter(func(key string) bool {
if key == joinedKeys {
return false
}
return true
}, keysPairs).([]string)
return keysPairs
},
"Get": func(keys ...string) string {
joinedKeys := strings.Join(keys, "")
keyPair, _, err := kvClient.Get(joinedKeys, nil)
示例3: consulKeys
func consulKeys(kv *api.KV, prefix string, lastIndex uint64) (interface{}, *api.QueryMeta, error) {
return kv.Keys(prefix, "", &api.QueryOptions{WaitIndex: lastIndex})
}