本文整理汇总了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})
}