当前位置: 首页>>代码示例>>Golang>>正文


Golang KV.Get方法代码示例

本文整理汇总了Golang中github.com/hashicorp/consul/api.KV.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang KV.Get方法的具体用法?Golang KV.Get怎么用?Golang KV.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/hashicorp/consul/api.KV的用法示例。


在下文中一共展示了KV.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: storeData

func storeData(kv *api.KV, key string, value []byte) {
	pair, _, err := kv.Get(key, nil)
	if err != nil {
		Error.Fatal("Failed reading from Consul for key:", key, "Error:", err)
	}
	if pair == nil || string(pair.Value) != string(value) {
		var p *api.KVPair
		if pair == nil {
			p = &api.KVPair{Key: key, Value: value}
		} else {
			p = &api.KVPair{Key: key, Value: value, ModifyIndex: pair.ModifyIndex}
		}
		success, meta, err := kv.CAS(p, nil)
		if err != nil {
			Error.Fatal(err)
		}
		if !success {
			storeData(kv, key, value)
		} else {
			Trace.Print("Request took: ", meta.RequestTime.Seconds(), " seconds")
			Info.Print("Updated key '", key, "' to '", string(value), "'")
		}
	} else {
		Trace.Print("not updating key", key)
	}
}
开发者ID:flyhard,项目名称:git2AnyConsul,代码行数:26,代码来源:storage.go

示例2: keyExists

func keyExists(key string, kv *consul.KV) bool {
	kp, _, err := kv.Get(key, nil)
	if err != nil {
		log.Warnf("Could not get key path %s: %v", key, err)
		return false
	}

	return kp != nil
}
开发者ID:CiscoCloud,项目名称:mantl-api,代码行数:9,代码来源:catalog.go

示例3: fetchConsul

func fetchConsul(kv *consul.KV, env string, key string) (value string, conf_err error) {
	pair, _, _ := kv.Get("go-sms/"+env+"/"+key, nil)
	if pair == nil {
		conf_err = errors.New("Failed to fetch \"" + key + "\" key for you environment. Leave default: " + defaults[key])
		value = defaults[key]
		return
	}

	value = string(pair.Value)
	return
}
开发者ID:hypersleep,项目名称:go-sms,代码行数:11,代码来源:consul.go

示例4: getSequencer

// getSequencer gets the lockindex, session id and the key which constitutes the sequencer for the current lock.
func getSequencer(kv *api.KV, key string) (*sequencer, error) {
	kvPair, _, err := kv.Get(key, nil)
	if err != nil {
		log.Println("Can't get the sequencer")
		return nil, err
	}
	if kvPair == nil {
		return nil, nil
	}
	seq := sequencer{}
	seq.lockIndex = kvPair.LockIndex
	seq.session = kvPair.Session
	seq.key = kvPair.Key
	return &seq, nil
}
开发者ID:samitpal,项目名称:consul-client-master-election,代码行数:16,代码来源:consul-client-master-election.go

示例5: NewConsulProvider

		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)
		if err != nil {
			log.Error("Error getting key ", joinedKeys, err)
			return ""
		}
		return string(keyPair.Value)
	},
	"Last": func(key string) string {
		splittedKey := strings.Split(key, "/")
		return splittedKey[len(splittedKey)-2]
	},
}

func NewConsulProvider() *ConsulProvider {
	consulProvider := new(ConsulProvider)
	// default values
开发者ID:hotelzululima,项目名称:traefik,代码行数:31,代码来源:consul.go

示例6: consulGet

func consulGet(kv *api.KV, key string, lastIndex uint64) (interface{}, *api.QueryMeta, error) {
	return kv.Get(key, &api.QueryOptions{WaitIndex: lastIndex})
}
开发者ID:nsaje,项目名称:dagger,代码行数:3,代码来源:consul.go


注:本文中的github.com/hashicorp/consul/api.KV.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。